I would like to have a different PYTHONPATH from my usual in a particular virtualenv. How do I set this up automatically? I realize that it's possible to hack the bin/activate
file, is there a better/more standard way?
You can deactivate a virtual environment by typing deactivate in your shell. The exact mechanism is platform-specific and is an internal implementation detail (typically, a script or shell function will be used).
Just put a file with a . pth extension (any basename works) in your virtualenv's site-packages folder, e.g. lib\python2. 7\site-packages , with the absolute path to the directory containing your package as its only contents.
PYTHONPATH — This environment variable tells the current python interpreter where it can look for additional libraries that you want to be able to import that may not be in the standard site-packages, or if you're going to add a separate site-packages directory.
This django-users post is probably going to help you a lot. It suggests using virtualenvwrapper to wrap virtualenv, to use the add2virtualenv command. Using this, when the environment is active, you can just call:
add2virtualenv directory1 directory2 ...
to add the directories to your pythonpath for the current environment.
It handles autonomously the PATH changes on environment switches. No black magic required. Et voila!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With