tags:

views:

127

answers:

3

Is there an official documentation on python website somewhere, on how to install and run multiple versions of python on the same machine? On linux?

I can find gazillions of blog posts and answers - but I want to know if there is a "standard" official way of doing this?

Or is this all dependent on OS?

A: 

It's most strongly dependent on the package distribution system you use. For example, with MacPorts, you can install multiple python packages and use the pyselect utility to switch the default between them with ease. At all times, you're able to call the different python interpreters by providing the full path, and you're able to link against all the python libraries and headers by providing the full paths for those.

So basically: whatever way you install the versions, as long as you keep your installations separate, you'll able to run them separately.

Seth Johnson
What is a package distribution system?
drozzy
@drozzy: For example RPM used by OpenSuse or apt used by Debian-based distributions or portage used by Gentoo etc. Basically it is a tool to install software.
Felix Kling
+2  A: 

I think it is totally independent. Just install them, then you have the commands e.g. /usr/bin/python2.5 and /usr/bin/python2.6. Link /usr/bin/python to the one you want to use as default.

All the libraries are in separate folders (named after the version) anyway.

If you want to compile the versions manually, this is from the readme file of the Python source code:

Installing multiple versions

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall".

For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.

Felix Kling
Thanks, the "make install" on primary and "make altinstall" on secondary made it clear.
drozzy
A: 

On windows, they get installed to separate folders (C:\python26 and C:\python31), but the executables have the same name (python.exe). I created another folder (C:\python) that contains two .bat files (python.bat and python3.bat) that serve as wrappers to python26 and python31, respectively, and added C:\python to the PATH env var. This allows me to type

python or python3 in my .bat python wrappers to start the one I desire.

On linux, you can use the #! trick to specify which version you want a script to use.

Brendan Abel