Running Django with Run can not find LESS CSS

2019-04-26 17:53发布

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

3条回答
小情绪 Triste *
2楼-- · 2019-04-26 18:30

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}'),
)
查看更多
Rolldiameter
3楼-- · 2019-04-26 18:34

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.

查看更多
一夜七次
4楼-- · 2019-04-26 18:36

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!

查看更多
登录 后发表回答