Python Upgrade – Upgrading to Python 2.7.5 on Ubuntu 12.04


Ubuntu 12.04 comes with python v 2.7.3 by default. I want to upgrade it to v 2.7.5. I tried the instructions given in this question,

sudo apt-get install build-essential
sudo apt-get install libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

cd ~/Downloads/

tar -xvf Python-2.7.5.tgz
cd Python-2.7.5

sudo make altinstall

The last command fails with the error:

Compiling /usr/local/lib/python2.7/ ...
Compiling /usr/local/lib/python2.7/ ...
make: *** [libinstall] Error 1

How can I make this upgrade?

Best Answer

Installing from source can be done, of course, but I would be hesitant to upgrade my Ubuntu systems' python package from source for several reasons:

  1. Doing so could break the system by doing a straight compile from source(I'm not exactly certain how Ubuntu customizes their Python package builds).

  2. I would be concerned that there might be issues with using modules from the repositories going forward.

There is a PPA that looks active(the 2.7.x train was last built in April of this year), but the PPA doesn't yet have a 2.7.5 build. You may want to ping the maintainer and see what their plans are for future builds and if they are going to include one for 2.7.5. If possible, I would recommend this over installing from source. As with any new software, I would recommending building this out on a test system first.

Another option is to use a sandbox(pyenv) to run any new untested software package. A straight installation onto your system could adversely impact the operation of your machine.

The package pyenv will allow one to install a non-system Python version on your box without impacting the main Python package installed on your machine( Again: Your system is dependent on the currently installed version of Python and upgrading it could break your system). Previously, Pythonbrew was recommended for isolating python packages from the system, but that has since been deprecated and superseded by the pyenv package.

The pyenv package provides the following functionality:

  • Lets you change the global Python version on a per-user basis.
  • Provides support for per-project Python versions.
  • Allows you to override the Python version with an environment variable.
  • Search commands from multiple versions of Python at a time.


  1. Check out pyenv into ~/.pyenv.

    git clone git:// .pyenv
  2. Add ~/.pyenv/bin to your $PATH for access to the pyenv command-line utility.

    echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile

    Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.

  3. Add pyenv init to your shell to enable shims and auto-completion.

    echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

    Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.

  4. Restart your shell so the path changes take effect. You can now begin using pyenv.

    exec $SHELL
  5. Install Python versions into ~/.pyenv/versions. For example, to install Python 2.7.5, download and unpack the source, then run:

    pyenv install 2.7.5

    NOTE If you need to pass configuration options to build from source, please use CONFIGURE_OPTS environment variable.

  6. Rebuild the shim binaries. You should do this any time you install a new Python binary (for example, when installing a new Python version, or when installing a package that provides a binary).

    pyenv rehash
Related Question