Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Django with Run can not find LESS CSS

I have a Django project that uses buildout. When running or debugging the application it runs fine by using my buildout script. I also use django-compressor to compress and compile my LESS files. I installed LESS server side with node and you can access the lessc binary from the shell as normal. django-compressor runs Popen to run the lessc command. When it does this and exception gets thrown: /bin/sh: lessc: command not found.

If I run /bin/sh lessc it finds it. If I drop into the interactive python and run Popen(['/bin/sh', '-c', 'lessc']) it finds it. What shell or environment does the running of Django in PyCharm use and how can I set it up to read either /etc/paths or $HOME/.bashrc, etc. lessc is located at /usr/local/bin which is in /etc/paths.

I am on Mac OSX 10.7, btw

Thanks for any support, Travis

like image 823
pistacchio Avatar asked Jun 29 '12 08:06

pistacchio


3 Answers

I had the same issue. To fix this I opened terminal and

$ which lessc

which gave me /usr/local/bin/lessc

next, in Pycharm i opened the Run/Debug configurations for my project.

Under the Django server drop down I selected my project.

In the configuration view to the right click the '...' after the 'Environment variables:' field.

In this Environment Variables window I added a new line with the following data: PATH (the name) /usr/local/bin (the value)

Ensure "Include parent environment variables" is checked.

Click OK Click Apply/OK

Done

Best of luck!

like image 65
Yup. Avatar answered Oct 05 '22 14:10

Yup.


As pointed in Django compressor docs, you can use:

COMPRESS_PRECOMPILERS = (
    ('text/less', 'lessc {infile} {outfile}'),
)

But probably for some reason Django could not find the lessc binary. So then just enter it with its full name:

COMPRESS_PRECOMPILERS = (
    ('text/less', '/usr/local/bin/lessc {infile} {outfile}'),
)
like image 40
Tisho Avatar answered Oct 05 '22 15:10

Tisho


You need the lessc binary. There's a few different ways to get it. Personally, I prefer to use the non-NodeJS method to install it (on Debian-based distros, like Ubuntu):

sudo apt-get install node-less yui-compressor

It will install it into one of the following locations:

/usr/local/bin/lessc
/usr/bin/lessc

Which, should be in your PATH already.

like image 32
eduncan911 Avatar answered Oct 05 '22 14:10

eduncan911