How do I make the terminal run python 3.1?

Use python-virtualenv to create a virtual python environment.

Select the version of Python to be created in the virtual environment:

virtualenv --python=/usr/bin/python3.1 myvirtualenv

To manage multiple virtual Python environments, install the virtualenvwrapper extension.

Why virtualenv?

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.


First of all, you need to install the python3 package. After installing it, go to a terminal and type:

sudo update-alternatives --config python

then choose python3 from the list that's presented.

If it does not work, you may need to recreate the symlink. First save it:

sudo mv /usr/bin/python /usr/bin/pythonSAVE

afterwards, create the alternatives:

sudo update-alternatives --install python2.5 python /usr/bin/python2.5 2
sudo update-alternatives --install python3.1 python /usr/bin/python3.1 1

create a new symlink:

sudo ln -s /etc/alternatives/python /usr/bin/python

Finally, choose the one (python3) you want to use:

sudo update-alternatives --config python

And if you need to go back to python2, just repeat the command:

sudo update-alternatives --config python

I guess just install the package and update-alternatives will work very well, you may don't need to recreate links from scratch. Thanks!

EDIT: As pointed out here the update-alternatives with the --install options accepts an absolute link, so you may need to run:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.1 1

First install Python 3.1 using the dead snakes repository: https://launchpad.net/~fkrull/+archive/deadsnakes

Then you can type 'python3' at the command line to run Python 3.1 while retaining the normal system Python.