views:

99

answers:

4

Background:

  • I am using Ubuntu
  • The newer python version is not in the apt-get repository (or synaptic)
  • I plan on keeping the old version as the default python when you call "python" from the command line
  • I plan on calling the new python using pythonX.X (X.X is the new version).

Given the background, how do you install a newer version of python and keep the older python version?


I have downloaded from python.org the "install from source" *.tgz package. The readme is pretty simple and says "execute three commands: ./configure; make; make test; sudo make install;"

If I do the above commands, will the installation overwrite the old version of python I have (I definitely need the old version)?

+4  A: 

When you install from source, by default, the installation goes in /usr/local -- the executable in particular becomes /usr/local/bin/pythonX.Y with a symlink to it that's named /usr/local/python. Ubuntu's own installation is in /usr/ (e.g., /usr/bin/python), so the new installation won't overwrite it. Take care that the PATH environment variable doesn't have /usr/local/bin before /usr/bin, or else simple mentions of python would execute the new one, not the old one.

Alex Martelli
probably you also want to use "make altinstall" instead of "make install", then it won't create /usr/local/bin/python (only pythonX.Y)
Ian Bicking
I also noticed that some people suggest changing the first "configure" step to use "./configure --prefix NEW_PATH". What does changing the --prefix option actually do? and why would you want to change it?
Trevor Boyd Smith
Please disregard the above question. The answer is explained by "./configure --help". The configure help also explains where the default installation is (which answers my other question of 'how do you find out what the default installation dir is').
Trevor Boyd Smith
+1  A: 

I'm just going to assume that by "newer version" you mean "released version that is newer than the default version in Ubuntu". That means python 3.1, which is in the repositories.

sudo apt-get install python3

Different python versions in the Ubuntu repositories can coexist with one another just fine. If you're on a version of Ubuntu older than Lucid, you'll have to upgrade your OS or enable the universe repository in order for python3 to show up in your package manager.

If you mean python 2.7, you should be aware that it hasn't been released yet.

Forest
+1  A: 

Just installed Python2.6 on Ubuntu 8.04.
first get all the required dependencies "apt-get build-dep python2.5" (The python 2.6 dependencies are the same as for 2.5)
apply the patch from http://www.lysium.de/sw/python2.6-disable-old-modules.patch:
patch -p1 < python2.6-disable-old-modules.patch

then ./configure --prefix=/opt/python2.6
make
sudo make install

sudo ln -s /opt/python2.6/bin/python2.6 /usr/local/bin/python2.6
it seems just works, default Python version is still 2.5. I save it at here, hope this helps.

sunqiang
I went to the link at the bottom of your answer. It seems like your way of installing python uses "easy_install". What are the advantages of "easy_install" over the "from source" install that I am doing?
Trevor Boyd Smith
I think the easy_install part was used for install the 3rd Python packages, for example ipython. easy_install needn't download, tar zxf, setup.py install, other wise I think it's only a personal taste, and build from source is fine too. but I don't think it has anything with install Python itself. maybe what I understand is not right for my broken English?
sunqiang
A: 

The Easy Way

  • Open up 'Synaptic Package Manager' from the menu
  • Search for 'python' in the 'Quick Search' field
  • Select and install whatever versions of python you choose to use

To use a specific version of python (Ex. 2.4) just type python followed by the version number in the terminal:

python2.4 run_some_script.py

To install libraries to a particular version of python just run setup.py the same way.

Ex. Install to python2.5

python2.5 setup.py install

In this day and age, there's really no need to build from source or worry about dependency tracking on most programs unless you're developing it directly or you're using a bleeding-edge non-stable branch.

If the newer stable revisions of python aren't showing up in apt-get or synaptic, update your repository.

  • in Synaptic press ctrl-r
  • in apt type 'apt-get update'

Note: You really should be able to get all the stable releases of python from 2.4 - 3.1 except 3.0 (because 3.0 has mainly been ditched as a result of the 'throw away' nature of the changes on that particular branch and the emergence of 3.1).

Evan Plaice