views:

78

answers:

3

I want to run multiple Python version in my box. Is there anything like version manager in Python where I can switch between multiple Python version without having to call the full path of the python binary? I have tried virtualenv and it seems to only cover problems running multiple python libraries version.

Thanks for your help.

+1  A: 

When calling python from bash you could try an alias.

user@machine:~$ alias python1234='/usr/bin/python2.5'
user@machine:~$ python1234
Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Let's say you have a script called script.py with following content:

import sys
print sys.version

So, launching a script with a different version of python looks like:

user@machine:~$ python script.py 
2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3]
user@machine:~$ python1234 script.py 
2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.3.3]
atomocopter
This might make sense for self-compiled pythons in weird locations such as /opt/my-python2.7/bin/python, but I don't see the point for Ubuntu-provided python2.5, which you can already call by a short name: 'python2.5'.
Marius Gedminas
A: 

You don't have to use the full path.

user@machine:$ python2.5
Python 2.5.5 (r255:77872, Sep 14 2010, 17:16:34) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

user@machine:$ python2.6
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Does that answer your question?

Marius Gedminas
Also, if you wanted just to type in `python` to run your version of choice at the moment, all that `python` is, is a symbolic link to `python2.5`, `python2.6`, etc., so you could make a link to those binaries in `/usr/bin`.
birryree
+1  A: 

I use virtualenv to keep track of different environments I need for my projects. I may setup django 1.0 in one environment or django 1.2 for another. You can use it to set which version of python you'd like to use in a particular environment as well. Here's the link to the site which has great samples and tutorials for how to get running: http://pypi.python.org/pypi/virtualenv

cmaxo
I like this approach. Didn't think of that. Will try it tonight.
jpartogi