开发者

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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜