TheMeaningfulEngineer
TheMeaningfulEngineer

Reputation: 16339

Does virtualenv just modify the pythonpath?

I'm deploying Django on a production server together with virtualenv, and am having trouble activating virtualenv on the server with

source .../bin/activate

I did a little research, and found that the pythonpath is changed depending on if we are or aren't in a virtualenv.

sys.path (with virtualenv activated)

['',
'/.../virtualenv/test_path/bin',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/.../virtualenv/test_path/lib/python2.7',
'/.../virtualenv/test_path/lib/python2.7/plat-linux2',
'/.../virtualenv/test_path/lib/python2.7/lib-tk',
'/.../virtualenv/test_path/lib/python2.7/lib-old',
'/.../virtualenv/test_path/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/IPython/extensions']

sys.path (without activating virtualenv):

['',
'/usr/local/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/local/lib/python2.7/dist-packages/IPython/extensions']

Is is sufficient to just change the pythonpath to point to the virtualenv

.../python2.7/site-packages

folder to get the same results as running

source .../bin/activate

?

Upvotes: 0

Views: 1663

Answers (1)

Hugo Lopes Tavares
Hugo Lopes Tavares

Reputation: 30384

No, it is not. virtualenv is not only about site-packages, it is about a whole isolated python environment.

Doing source /path/to/venv/bin/activate just changes your $PATH environment variable to include your virtualenv bin directory as first lookup.

If you call python directly, it is just a shortcut for:

$ /path/to/venv/bin/python myscript.py

And if you call pip in an activated virtualenv, it is the same as:

$ /path/to/venv/bin/pip install XYZ

Upvotes: 2

Related Questions