Running multiple python versions

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

Thank you for your help.

+5
source share
3 answers

I use virtualenv to track the various environments I need for my projects. I can configure django 1.0 in one environment or django 1.2 for another. You can use it to indicate which version of python you want to use in a particular environment. Here's a link to a site that has great samples and tutorials to run: http://pypi.python.org/pypi/virtualenv

+6
source

When calling python from bash, you can 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 the following contents:

import sys
print sys.version

So, running a script with another version of python looks like this:

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]
+8
source

You do not need 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 this answer your question?

+4
source

All Articles