How to install and manage different versions of Python in Linux

Here is an interesting post on how to install / manage different versions of Python in a single linux / ubuntu machine!

Pythonbrew is a magical tool. Which can also be called as Python version manager similar to that of RVM-Ruby version manager but Pythonbrew is inspired by Perlbrew.

Pythonbrew is a program to automate the building and installation of Python in the users $HOME.

Dependencies – curl

Before Installing the Pythonbrew, Install “curl” in the machine, to install curl use the below command in the terminal, give the the password for the user when prompted.

sudo apt-get install curl

After Installing the curl, Now Install Pythonbrew, copy and paste the following commands in the terminal and type the password for the user when prompted.

Recomended method of installation – Easy Install

sudo easy_install pythonbrew 

To complete the installation, type the following command

pythonbrew_install

Alternate method of installation:

Use curl command to download the latest version of pythonbrew from github.

curl -kLO http://github.com/utahta/pythonbrew/raw/master/pythonbrew-install

After downloading, change “pythonbrew-install” to “executable”

chmod +x pythonbrew-install

Then, run the pythonbrew-install in the terminal

./pythonbrew-install

Now the Pythonbrew has been installed in the “Home Directory” i.e., /home/user/.pythonbrew

Next, copy and paste the following line to the end of  ~/.bashrc

*NOTE: change “user” to your user name in the system

source /home/user/.pythonbrew/etc/bashrc

Thats it! Close the terminal.

Steps to Install different versions of Python:

Open a new terminal, type the following command or copy and paste it.

pythonbrew install 2.6.6

This will install Python 2.6.6 and to install Python 2.7 or Python 3.2, change the version number in the previous command.

pythonbrew install 2.7

or

pythonbrew install 3.2

Update: If you get error while Installing then Install using the below command.

pythonbrew install --force 2.7

or

pythonbrew install --force 3.2

How to manage different versions of Python installed in system

For instance, if Python 2.6.6, Python 2.7 and Python 3.2 is installed in your system, switching between the versions can be done as follows:

By default, Python 2.6.6 will be active and in order to switch to Python 2.7 use the below command

pythonbrew switch 2.7

The default Python is changed to Python 2.7.

Now, to switch to Python 3.2 change the version number in the previous command.

pythonbrew switch 3.2

Use the below command to check or list the installed Python versions

pythonbrew list

Use the below command to check or list the available Python Versions to install

pythonbrew list -k

To uninstall any of the installed Python version (for example to uninstall Python 2.7), use the below command.

pythonbrew uninstall 2.7

Use the below command to update the Pythonbrew

pythonbrew update

Use the below command to disable the Pythonbrew and to activate the default version

pythonbrew off

Enjoy the experience of installing multiple versions of Python in single Linux / ubuntu machine!

Update: For Debian Users there is an alternative method in this site-http://www.stylesen.org/python_27_debian_squeeze_60

Related Posts Plugin for WordPress, Blogger...

  • http://tamilcpu.blogspot.com Rajkumar Ravi

    nice tutorial.. my friend wants to start learning python with his virtually installed ubuntu os. i came across this article at right time. thank you.

    • http://www.howopensource.com Manivannan

      Thanks Rajkumar :)

  • Collin David

    Good work mani.. Keep going..

  • Chandar, Singapore

    Excellent Tutorial Mani..Keep it up..

    Wishes from-
    Vadivu
    Chandar
    Subbu

    Singapore

  • Mayank

    Thank you so much. You saved my day…. been looking how to do this on fedora…

  • Arulmozhi

    I want activate DHCP and using dual Ethernet, Please help me and i want activate thin client server also and i want share internet also…..

    thanking you Sir…,

  • Derek

    Thanks for the clear instructions. But I would just add a couple things.

    Use the full version number when installing a Python version, e.g. “pythonbrew install 3.2.1″, if it is available. Otherwise, e.g. for “3.2”, you will get the oldest version of 3.2, not the latest 3.2.

    Also, make sure you have Python’s build dependencies installed before installing Python. For installing 3.2.1 on Ubuntu 10.10, I ran this:
    $ sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev libbz2-dev
    $ pythonbrew install 3.2.1

    • http://www.howopensource.com Manivannan

      Hi Derek,

      Thanks and Welcome to HowOpenSource :)

  • Pingback: How to install and manage different versions of Python in Linux « thoughts…()

  • Afiz Momin

    I am getting error… pythonbrew not found. Here are the steps that i followed..

    After downloading, change pythonbrew-install to executable file,
    chmod +x pythonbrew-install

    Then, run the pythonbrew-install in the terminal
    ./pythonbrew-install

    To change directly to home, cd ~
    To list all the files in directory: ls -la, ls -a |grep bashrc

    After installing, change

    • http://www.howopensource.com Manivannan

      Hi Afiz,

      May I know which distro your using and its version.

  • prabu

    it is working properly as your instruction

    After that I tried to install some additional software.
    sudo easy_install-2.6 sqlalchemy==0.4.5.

    It is showing the commannd is not found.please help me here

  • Gordon Morehouse

    These alternate Debian instructions may be a bad plan — check the comments on that post.

  • Vitaly

    Thank you so MUCH!!!
    Muchisimas gracias!!!