Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenv on Windows: not over-riding installed package

My current setup is Python 2.5/ Django 1.1.1 on Windows. I want to start using Django 1.2 on some projects, but can't use it for everything. Which is just the sort of thing I've got virtualenv for. However, I'm running into a problem I've never encountered and it's hard to Google for: installing Django 1.2 into a virtualenv has no effect for me. If I then activate the environment and do

  • python
  • import django
  • django.VERSION

I get "1.1.1 Final". Django is installed in the site-packages directory of my environment and the init file in the root shows that it is 1.2. But the environment falls back to 1.1.1, even if I create the environment with the --no-site-packages flag. What am I screwing up?

like image 461
Tom Avatar asked Dec 23 '22 02:12

Tom


2 Answers

Based on the bug you filed at bitbucket, it looks like you're using the PYTHONPATH environment variable to point to a directory with some packages, including Django 1.1.1. By design, PYTHONPATH always comes first in your sys.path, even when you have a virtualenv activated (because PYTHONPATH is under your direct and immediate control, and people use it for local overrides).

In this case, if you don't want that PYTHONPATH when this virtualenv is activated, you'll need to take care of that yourself; perhaps by creating a custom batch file that both calls the virtualenv's activate.bat and also modifies PYTHONPATH.

like image 179
Carl Meyer Avatar answered Dec 31 '22 12:12

Carl Meyer


Some tools you can use to diagnose these problems:

To see where django is coming from, print django.__file__. It will show the file indicating django's location on the file system.

To see all the places Python will look for packages, print sys.path. It's a list of directories.

To see imports as they happen, start python as python -v, and you'll see lots of debugging information about where packages are being imported.

like image 29
Ned Batchelder Avatar answered Dec 31 '22 14:12

Ned Batchelder