enderland
enderland

Reputation: 14145

Why does PyCharm sometimes not use system environment variable for PATH with a virtual environment?

Using PyCharm, I have configured a virtual environment. This results in some really confusing interactions with PATH. When I look at the environment variable for PATH that a file has:

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

I see the following output:

##### PATH
 /usr/bin:/bin:/usr/sbin:/sbin:/Users/username/.virtualenvs/venv/bin

This confuses me because I have explicitly told PyCharm to use system environment variables through the following dialog:

enter image description here

When clicking "Show" I see that PATH is defined differently:

enter image description here

What I do not understand is:

  1. Running PyCharm from a shell using charm results in PATH being successfully set:

    ##### PATH
    /Users/username/.virtualenvs/username/bin:/Users/username/go/dependencies/bin:/usr/local/go/bin:/usr/local/go/bin:/usr/local/bin:.... etc
    

    This is without any other configuration taking place in PyCharm - simply relaunching it from a shell causes PATH to behave set differently

  2. I can also manually define the PATH variable in PyCharm (to the value given in the parent environment variables tab) and it works fine, too

But for some reason PyCharm is not pulling the PATH variable from my parent environment variables even though it is present and appears to be included properly (without either of the above two workarounds).

Why is PyCharm doing this and what do I need to do to actually "include parent environment variables" correctly?

I am using PyCharm 5.0.4 on OS:X with a bash shell.

Upvotes: 12

Views: 3502

Answers (2)

slallum
slallum

Reputation: 2241

It is a known bug in pycharm and OS X: https://youtrack.jetbrains.com/issue/PY-17816

Upvotes: 1

Dan Schien
Dan Schien

Reputation: 1412

You need to start python from the command line if you want to inherit those variables.

To create a shortcut select "Tools> Create Command-line launcher".

Upvotes: 0

Related Questions