开发者

On Ubuntu, how do you install a newer version of python and keep the older python version?

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)?


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.


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜