Virtualenv - non-site-packages do not work for me

virtualenv --no-site-packages v1 cd v1\Scripts activate.bat python -c "import django" # - no problem here 

Why does he see a Django package ??? This should result in an import error, right?

+7
source share
2 answers

Just disable the PYTHONPATH environment variable. The idea behind virtualenv is that you can create your own environment (completely isolated or expanding by default) so you don't have to deal with it.

As someone noted, there was already a similar question on SO . Read it if you need a better explanation.

+9
source

It should not raise any ImportError while there is a django package in sys.path .

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

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

Then check Python "Module Path" .

UPDATE: As pointed out in the comments: note that the --no-site-packages option in virtualenv removes only the standard package site directory from sys.path . The remaining paths remain unchanged.

+2
source

All Articles