views:

250

answers:

2

I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6.

Here is how it was originally set up:

virtualenv --no-site-packages -p python2.5 myenv

I now run virtualenv in the same directory to upgrade:

virtualenv --no-site-packages -p python2.6 myenv
...
Not overwriting existing python script myenv/bin/python (you must use myenv/bin/python2.6)
...
Overwriting myenv/bin/activate with new content

The default python is still 2.5, even though I can also specify 2.6. Is there any way to remove 2.5 entirely and have 'bin/python' point to 2.6 instead?

+2  A: 

You should create a new virtualenv using python2.6 and then, after activating the new env, use its python2.6 and its easy_install to install new versions of any site packages you need. Beware that the path name to the virtualenv is hardwired into various files within the environment, so, when you are ready to switch over to it, either change your startup scripts et al to refer to the new virualenv path or be very careful about copying it over to the old directory and modifying the path names inside it.

Ned Deily
+2  A: 

You can use the Python 2.6 virtualenv to "revirtual" the existing directory. You will have to reinstall all the modules you installed though. I often have a virtual directory for developing a module, and virtualenv the same directory with many versions of Python, and it works just fine. :)

Lennart Regebro
Thanks! I tried your method and see that the 'activate' script is updated, but the old version remains (please see the revised question). Are you able to provide an example?
Wraith
you can just remove the bin/python executable in the virtualenv before re-running virtualenv with python 2.6.
Carl Meyer
Perfect! Thanks!
Wraith
Well, you *can* make it work - but why? The big attraction of `virtualenv` is that it easily and cheaply makes reproducible python environments. Why muck with one and not be certain you've fixed up everything or that you can reproduce it again or that you're disturbing your production environment when you can just make a new clean one?
Ned Deily
@Wraith: You can just delete bin/python before running virtualenv, or just delete it afterwards and make a new soft-link to bin/python2.6
Lennart Regebro
@Ned: Virtualenv doesn't make reproducible environments, it makes isolated environments. To reproduce them you need also to install everything the same way, virtualenv isn't enough for that. zc.buildout is better there.
Lennart Regebro
@Lennart: `Isolated` is indeed a better description. Even so, the other points still stand.
Ned Deily
@Ned: I agree I wouldn't do this for a production environment, but then I would use buildout for production anyway, and also typically separate compiled Pythons, which makes virtualenv completely superfluous. :)
Lennart Regebro
@Ned: Point taken; this is a development environment I was working in. I wanted to keep it in 2.5 unless I absolutely needed to do 2.6. That need arose, so I was curious if you could upgrade an isolated environment to see the effects on your code, without having to rebuild and copy/paste directories to the new env.
Wraith