Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Python 2.6 in Ubuntu 11.10?

The default version of Python on Ubuntu 11.10 is 2.7, but I'm looking for 2.6. How do I make it default and where is the executable located?

I type which python2.6 but it returns nothing, yet I did have a python2.6 folder under /usr/lib/python2.6. But it doesn't look like the python2.7 which is at the same path /usr/lib/. Inside the python2.6, there are two folders: dist-packages and lib-dynload.

Actually I am configuring PyDev, and it requires me to specify where the python2.6 executable is. The python2.7 executable has been easily located by just using auto configuration as it is the default.

like image 635
Kevin Avatar asked Nov 17 '11 06:11

Kevin


People also ask

How do I install a specific version of Python in Ubuntu?

First, we change the current directory to the Downloads folder where we wish to download the package. This can be done by running the command below. The next step is to “wget” the package from the Python website. Click here to access the location from where you can select any version of Python of your liking.


2 Answers

You can install the package python2.6 (apt-get install python2.6). At this point, the default version of Python will still be 2.7. You can change this via

ln -s /usr/bin/python2.6 /usr/bin/python

Note that there's a decent chance this could cause problems with your system. Several scripts assume the default version of Python is 2.7 and may break when run under a different version. If you have a script that explicitly requires Python 2.6, you can add a shebang at the beginning of your script to specify the version

#!/usr/bin/python2.6
like image 73
Michael Mior Avatar answered Oct 14 '22 01:10

Michael Mior


On many systems, one version of python is the default. The rest get called by their name and version number:

~ $ python --version
Python 2.7.2
~ $ python2.6 --version
Python 2.6.7

Per the release notes, these should be available in Oneiric.

Your other questions:

  • Where is it? Run $ which python2.6 to find out.
  • How to make it the default? The safest way is to use alias so that change will be only visible to you. Otherwise, if you repoint /usr/bin/python to an unexpected version of Python, you will may break the OS scripts that rely on Python2.7. Rather than changing the default, it is better to just call the specific version of Python you need.
like image 23
Raymond Hettinger Avatar answered Oct 14 '22 01:10

Raymond Hettinger