Walrus the Cat
Walrus the Cat

Reputation: 2404

python virtualenv -- possible to augment $PATH or add other environment variables?

I'd like to alter my $PATH only in a Python virtual environment. Is it possible to have the $PATH change when I activate a virtual environment?

Upvotes: 0

Views: 197

Answers (2)

tdelaney
tdelaney

Reputation: 77347

You can write an activation script that sources virtualenv's activate (on linux, or calls the bat file on windows) and then updates PATH, PYTHONPATH and other environment variables. Use the virtualenv bootstrap hooks to install the script when the virtualenv is created and call it instead of activate.

Upvotes: 1

drsnark
drsnark

Reputation: 3033

Depending on what operating system you are using you could edit the activate file and set an environment variable there. For example, a Windows virtualenv folder has a sub-folder called Scripts. Inside scripts is the activate.bat file. Edit activate.bat and alter the path variable. One thing to consider though, is you might want to save the original path variable in another temporary environment variable and restore from that temporary environment variable in the deactivate.bat file.

Upvotes: 0

Related Questions