wmfox3
wmfox3

Reputation: 2221

How to use different version of Django in virtualenv

I'm trying to run Openblock within a virtualenv, but the problem is Openblock requires Django 1.2.5 and I've already got Django 1.1.1 on the server.

$ python -c "import django;print django.get_version()" returns 1.1.1

After activating the virtualenv, the same command returns 1.2.5. So far so good.

But when I run yolk -l within the virtualenv it shows 1.1.1 as active and 1.2.5 as non-active.

Upvotes: 2

Views: 985

Answers (2)

beer_monk
beer_monk

Reputation: 956

Virtualenv updates sys.path

run this in and out of the virtualenv to debug.

python -c "import sys; print '\n'.join(sys.path)"
python -c "import os; print os.getenv('PYTHONPATH')

Try creating the virtualenv with --no-site-packages and see if it still conflicts.

Upvotes: -1

Nicholas Riley
Nicholas Riley

Reputation: 44321

You need to install yolk into the virtualenv otherwise it'll list system packages instead; yolk doesn't know anything about the current virtualenv. So run pip install yolk with the virtualenv activated. (If you've created your virtualenv without --no-site-packages, you'll need to run pip install --upgrade yolk).

I just recreated this scenario (except with Debian squeeze where the OS version of Django is 1.2.3) and it worked. With --no-site-packages:

% . foo/bin/activate
(foo)% yolk -l Django
Django          - 1.2.5        - active 
(foo)% deactivate

and without:

% . bar/bin/activate
(bar)% yolk -l Django
Django          - 1.2.3        - non-active development (/usr/lib/pymodules/python2.6)
Django          - 1.2.5        - active 

In general, if you run any Python programs installed outside the virtualenv, you shouldn't expect them to know anything about the virtualenv unless they've been written to be aware of virtualenv (e.g. pip's PIP_RESPECT_VIRTUALENV).

Upvotes: 7

Related Questions