Currently, when I type "python" at the terminal I get v2.6 which is all fine and dandy but how can I set it to use v3.1 instead? Is there a "path" variable out there somewhere that I can change like windows?

EDIT: I already have python3 installed and up and running. I just want to know how to set it as the shells default python version.

  • python3 vs python from the command line. – earthmeLon Jul 18 '12 at 14:17

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.

| improve this answer | |
  • If my app ever goes public I will definitely use this thank you. – John Nov 24 '10 at 17:15

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
| improve this answer | |
  • I tried running sudo update-alternatives --config python, but it tells me update-alternatives: error: no alternatives for python. I tried recreating the symlink as you said but it doesn't semm to change anything... What could be wrong? – Sean Bone Jun 27 '14 at 9:52

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.

| improve this answer | |
  • +1 - Seems pointless, since python3.1-minimal is in the Ubuntu repositories, but actually this repository contains python2.4 and python2.5 - which is rather nice. (I have to use python 2.4 for high performance computing, know the pain...) – Stefano Palazzo Nov 24 '10 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.