Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a path to PYTHONPATH in virtualenv

I am trying to add a path to the PYTHONPATH environment variable, that would be only visible from a particular virtualenv environment.

I tried SET PYTHONPATH=... under a virtualenv command prompt, but that sets the variable for the whole environment.

How do I achieve that?

like image 259
Flavien Avatar asked May 24 '12 13:05

Flavien


People also ask

How do I add Pythonpath to Virtualenv?

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.

How do I change the environment variable in Pythonpath?

If you are on Windows In the Environment variables dialog, click the “New” button in the top half of the dialog, to make a new user variable: Give the variable name as PYTHONPATH and the value is the path to the code directory. Choose OK and OK again to save this variable.


2 Answers

You can usually avoid having to do anything with PYTHONPATH by using .pth files. 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.

like image 70
Danica Avatar answered Oct 11 '22 17:10

Danica


If you're using virtualenv, you should probably also be using virtualenvwrapper, in which case you can use the add2virtualenv command to add paths to the Python path for the current virtualenv:

add2virtualenv directory1 directory2 …

like image 28
crimeminister Avatar answered Oct 11 '22 18:10

crimeminister