Django Sass Compressor django_libsass.SassCompiler: command not found

I use the Django-Compressor filter as part of Wagtail (version with the Django CMS version with a super-cool interface). The environment is Wagtail 0.2 + Python 2.7 + Django 1.6 + Virtualenv + FastCGI + Apache sharing.

The problem occurs when trying to access the CMS administration / login page. Django shows error handling pattern

Error during template rendering In template /home/username/env/lib/python2.7/site-packages/wagtail/wagtailadmin/templates/wagtailadmin/skeleton.html, error at line 20 /bin/sh: django_libsass.SassCompiler: command not found 

Line 20 of the skeleton.html file:

  <!doctype html> {% load compress %} <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="{{ LANGUAGE_CODE|default:"en-gb" }}"> <!--<![endif]--> <title>Wagtail - {% block titletag %}{% endblock %}</title> <meta name="description" content="" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> {% block css %}{# Block defined for timing breakdowns in django debug toolbar - not expected to be overridden #} <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" /> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Bitter:400,700" /> 19 20 {% compress css %} 21 <link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/normalize.css" /> <link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/vendor/jquery-ui/jquery-ui-1.10.3.verdant.css" /> <link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/vendor/jquery.timepicker.css" /> <link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/core.scss" type="text/x-scss" /> {% endcompress %} {% block extra_css %}{% endblock %} {% endblock %} </head> <body class="{% block bodyclass %}{% endblock %} {% if messages %}has-messages{% endif %}"> 

precompiler in my settings.py, DEBUG is set to True:

 COMPRESS_ENABLED = True COMPRESS_PRECOMPILERS = ( ('text/x-scss', 'django_libsass.SassCompiler'), ) 

CORRECTION AND ERROR No. 1

I tried switching to:

 ('text/x-scss', '/home/username/env/lib/python2.7/site-packages/django_libsass {infile} {outfile}') 

but this leads me to a dictionary update sequence item error.

I have django_libsass and compressor installed, also tried pip install libsass , ngm install lessc , pip install sass , turning DEBUG = False , adding COMPRESSOR_OFFLINE , adding COMPRESSOR_ENABLED , as suggested in other similar questions. Running manage.py compress returns the same error.

Rechecked and package sites and django_libsass really reside on my sys.path

SassCompiler can be found in ~/env/lib/python2.7/site-packages/django_libsass.py

CORRECTION AND ERROR No. 2

Re-checked that sass installed in my path sass .

Change code to:

 COMPRESS_PRECOMPILERS = ( ('text/x-scss', 'sass --scss {infile} {outfile}'), ) 

It returns an error:

 Exception Type: FilterError Exception Value: /bin/sh: sass: command not found 

CORRECTION AND ERROR No. 3

After reading this release feed , tried pip install compass without effect

CORRECTION AND ERROR No. 4

Following gasman's comment, I ran python manage.py shell and tried to import SassCompiler. It works without errors.

  Python 2.7.6 (default, Nov 11 2013, 18:34:29) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django_libsass import SassCompiler >>> 

Full trace

I apologize if this question is too long.

 Traceback: File "/home/username/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 139. response = response.render() File "/home/username/env/lib/python2.7/site-packages/django/template/response.py" in render 105. self.content = self.rendered_content File "/home/username/env/lib/python2.7/site-packages/django/template/response.py" in rendered_content 82. content = template.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render 140. return self._render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. return node.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render 123. return compiled_parent._render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. return node.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render 62. result = block.nodelist.render(context) File "/home/username/env/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) File "/home/username/env/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. return node.render(context) File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render 147. return self.render_compressed(context, self.kind, self.mode, forced=forced) File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render_compressed 107. rendered_output = self.render_output(compressor, mode, forced=forced) File "/home/username/env/lib/python2.7/site-packages/compressor/templatetags/compress.py" in render_output 119. return compressor.output(mode, forced=forced) File "/home/username/env/lib/python2.7/site-packages/compressor/css.py" in output 51. ret.append(subnode.output(*args, **kwargs)) File "/home/username/env/lib/python2.7/site-packages/compressor/css.py" in output 53. return super(CssCompressor, self).output(*args, **kwargs) File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in output 246. content = self.filter_input(forced) File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in filter_input 194. for hunk in self.hunks(forced): File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in hunks 169. precompiled, value = self.precompile(value, **options) File "/home/username/env/lib/python2.7/site-packages/compressor/base.py" in precompile 226. **kwargs) File "/home/username/env/lib/python2.7/site-packages/django_libsass.py" in input 51. return compile(filename=self.filename) File "/home/username/env/lib/python2.7/site-packages/django_libsass.py" in compile 41. return sass.compile(**kwargs) Exception Type: AttributeError at /admin/login/ Exception Value: 'module' object has no attribute 'compile' 
+6
source share
4 answers

(By sending my comments as an answer, as requested ...)

Original error: django_libsass.SassCompiler: command not found

meant that he was unable to import the django-libsass library. (django-compressor responded to this failure by trying to treat it as a shell command instead - django_libsass is not an executable command, so it didn't work either, giving the real error seen here.) The solution is to install django-libsass - it should be displayed on pip freeze output.

Second error: 'module' object has no attribute 'compile'

meant that another package was installed that defined a module called sass , and this was loaded instead of the one we wanted from the libsass package. The solution is to remove all sass related packages except django-libsass and libsass.

+7
source

I had the same problem with my Python-Django and rvm project. The problem is that the compression precompiler does not know which rvm to use. The solution is to add the ruby ​​path to the environment and tell the precompiler where to find the sass in the settings.py file:

As in my case (just which sass to find the path):

  environ['PATH'] = '/Users/username/.rvm/gems/ruby-2.1.5/bin:/Users/username/.rvm/gems/ ruby-2.1.5@global /bin:/Users/username/.rvm/rubies/ruby-2.1.5/bin:Users/username/bin' COMPRESS_PRECOMPILERS = ( ('text/x-scss', '/Users/username/.rvm/gems/ruby-2.1.5/bin/sass --scss --trace {infile} {outfile}'), ) 

Hope this helps someone.

+1
source

Error

 /bin/sh: django_libsass.SassCompiler: command not found 

Indicates that the Django Compressor is trying to run django_libsass.SassCompiler as a shell command, and the script is not running.

This is because django_libsass.SassCompiler not a valid program that can be run from the command line.

It is best to install sass first if you have not already done so by following the instructions on this page: http://sass-lang.com/install

Then change your code to:

  COMPRESS_PRECOMPILERS = ( ('text/x-scss', 'sass --scss {infile} {outfile}'), ) 

You must be sure that the sass command is on your way.

In the docs ( http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_PRECOMPILERS ) the second part of your tuple:

Command to call each of the files. Modern string formatting in Python will be provided for two placeholders {infile} and {outfile}, the existence of which on the command line also triggers the actual creation of these temporary files. If the command line is not specified, Django Compressor will use stdin and stdout instead.

0
source

pip install django_pyscss fix your problem.

-1
source

All Articles