PyCharm Command Not Found When Using Virtualenv & MacPorts

I recently switched a project over to using virtualenv for my PyCharm Django server run/debug configuration and ran into a ‘command not found’ error when trying to use another MacPorts installed package (sass) from Django (via Django Compressor).

Here is my original server configuration in PyCharm:

A quick look at the PATH environment variable identified the trouble:

MacPorts Python (/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)

>>> print os.environ['PATH']

Virtualenv Python (/Users/chriskief/.virtualenvs/exampleproject/bin/python)

>>> print os.environ['PATH']

The MacPorts bin and sbin are missing from the PATH, and that’s where sass lives:

which sass

The solution is to add the MacPorts directories (/opt/local/bin:/opt/local/sbin:$PATH) to your environment variables’ PATH in the run/debug configuration:

As a side note, if you run the Django server using the virtualenv from your terminal, you won’t encounter this error because MacPorts includes these directories in your .profile PATH:

# MacPorts Installer addition on 2013-10-26_at_16:30:30: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s