Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenv --no-site-packages is not working for me

virtualenv --no-site-packages v1

cd v1\Scripts

activate.bat

python -c "import django" # - no problem here

Why does it see the Django package??? It should give me an import error, right?

like image 481
agend Avatar asked Feb 13 '11 22:02

agend


2 Answers

Just unset PYTHONPATH environment variable. The idea of virtualenv is that you can create your own environment (fully isolated or extending the default one) so you don't have to mess with that.

As someone noticed there's already been a similar question on SO. Read it if you need a better explanation.

like image 93
Tomasz Elendt Avatar answered Nov 09 '22 12:11

Tomasz Elendt


It should not raise any ImportError as long as there is a django package in the sys.path.

If you're wondering where django comes from, run:

python -c "import django; print django.__file__"

Then check Python's Module Search Path.

UPDATE: As pointed out in the comments: Take into account that the --no-site-packages option in virtualenv only removes the standard site-packages directory from sys.path. The other paths just remain the same.

like image 42
scoffey Avatar answered Nov 09 '22 10:11

scoffey