views:

96

answers:

2

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?

+2  A: 

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.

Ned Batchelder
Thanks. Looking at sys.path, the virtualenv folders are at the end of the list. Shouldn't they be at the start?
Tom
When I use virtualenv on windows, I get the virtualenv dirs first, then the standard dirs. Are you using activate.bat?
Ned Batchelder
+1  A: 

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.

Carl Meyer
Thanks for your help there and here. I'm a putz. No idea why I had anything in my PYTHONPATH variable, but clearing it out sure makes a difference. I guess I thought PYTHONPATH was the only path info Python used.
Tom