2

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.

Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
wmfox3
  • 2,141
  • 4
  • 21
  • 28

2 Answers2

7

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

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
  • I've done that, Nicholas. Is it possible yolk is showing both versions of Django -- the system package 1.1.1 and the virtualenv package 1.2.5. – wmfox3 Feb 18 '11 at 23:42
  • Are you sure you're running the virtualenv version of yolk? Try `which yolk` and make sure it's what you expect. To be absolutely sure, you could recreate your virtualenv with `--no-site-packages` so there's no possibility the system version of Django gets used. – Nicholas Riley Feb 18 '11 at 23:45
  • You're right. That returns '/usr/local/bin/yolk'. I'm assuming I can't install yolk in the virtualenv because it's already got the site package. – wmfox3 Feb 18 '11 at 23:56
  • You can, you just need to use `pip install --upgrade`. However, I think you'd stay a lot saner if you recreated your virtualenv with `--no-site-packages` so it was more thoroughly isolated from the system. – Nicholas Riley Feb 19 '11 at 00:00
-1

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.

beer_monk
  • 946
  • 7
  • 7
  • When I run 'pip install yolk' while the virtualenv is active, I get: 'Requirement already satisfied (use --upgrade to upgrade): yolk in /usr/local/lib/python2.6/dist-packages/yolk-0.4.1-py2.6.egg Requirement already satisfied (use --upgrade to upgrade): distribute in /usr/local/pythonenv/openblock/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg (from yolk)' – wmfox3 Feb 18 '11 at 23:49
  • I'm confused. I created a new virtual environment with --no-site-packages, activated the virtual environment and ran yolk without even installing it. And it showed dozens of packages installed in the virtualenv despite using the option --no-site-packages. – wmfox3 Feb 19 '11 at 00:04
  • That's right - you're still running the system version of yolk. You need to install yolk into the virtualenv - see my answer, again... – Nicholas Riley Feb 19 '11 at 00:21
  • Virtualenv does nothing with PYTHONPATH. – Carl Meyer Feb 27 '11 at 05:05