How do you set your pythonpath in an already-created virtualenv?

TIMEX picture TIMEX · Jan 21, 2011 · Viewed 126.8k times · Source

What file do I edit, and how? I created a virtual environment.

Answer

mdeous picture mdeous · Jan 21, 2011

EDIT #2

The right answer is @arogachev's one.


If you want to change the PYTHONPATH used in a virtualenv, you can add the following line to your virtualenv's bin/activate file:

export PYTHONPATH="/the/path/you/want"

This way, the new PYTHONPATH will be set each time you use this virtualenv.

EDIT: (to answer @RamRachum's comment)

To have it restored to its original value on deactivate, you could add

export OLD_PYTHONPATH="$PYTHONPATH"

before the previously mentioned line, and add the following line to your bin/postdeactivate script.

export PYTHONPATH="$OLD_PYTHONPATH"