6
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?

bluish
  • 26,356
  • 27
  • 122
  • 180
agend
  • 648
  • 1
  • 8
  • 18
  • what `python -c "import sys; print sys.executable"` produces? – jfs Feb 13 '11 at 22:15
  • @j.f. : v1\Scripts\python.exe – agend Feb 13 '11 at 22:34
  • @agend: Are sure that it is a new environment? Try to create an environment that doesn't exists already e.g., `virtualenv --no-site-packages 4fd700ca` – jfs Feb 13 '11 at 22:56
  • `D:\kod_django>virtualenv --no-site-packages v5 New python executable in v5\Scripts\python.exe Installing setuptools.....................done. D:\kod_django>cd v5\Scripts D:\kod_django\v5\Scripts>activate.bat (v5) D:\kod_django\v5\Scripts>python -c "import sys; print sys.executable" D:\kod_django\v5\Scripts\python.exe ` – agend Feb 13 '11 at 23:01
  • @j.f. - made a fresh one - didn't change anything, sorry i can't format the last comment correctly – agend Feb 13 '11 at 23:07
  • 2
    Did you mess with `PYTHONPATH`? – Tomasz Elendt Feb 13 '11 at 23:10
  • @tomasz - hi, what do you mean by mess with... What should be a correct pythonpath? – agend Feb 13 '11 at 23:13
  • Did you set `PYTHONPATH` environment variable by yourself? – Tomasz Elendt Feb 13 '11 at 23:17
  • @tomasz - actually it helped - make a post, i'll mark it as an answer, thanks – agend Feb 13 '11 at 23:32
  • 1
    related: `PYTHONPATH` http://stackoverflow.com/questions/2961103/virtualenv-on-windows-not-over-riding-installed-package/2963017#2963017 – jfs Feb 13 '11 at 23:35
  • I have a similar problem, and the issue is nothing to do with PYTHONPATH and seems to be that Windows is ignoring the PATH variable. I don't have a fix as yet. – Kylotan Oct 10 '11 at 18:11

2 Answers2

9

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.

Community
  • 1
  • 1
Tomasz Elendt
  • 1,475
  • 13
  • 14
2

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.

scoffey
  • 4,638
  • 1
  • 23
  • 27
  • yeah, i know it's coming from somewhere, but i don't want to see it after activating virtualevn environment - what should i do ? do i have to set my python/system path by hand ? i was expecting virtualenv to do it for me – agend Feb 13 '11 at 23:19
  • 4
    Yes, virtualenv modifies the module search path (`sys.path`). But finding out where `django` is may help you fix the isolation of packages. The `--no-site-packages` just removes the standard site-packages directory from `sys.path`. Everything else just remains there. – scoffey Feb 13 '11 at 23:34