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/
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz

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/xmlrpclib.py ...
Compiling /usr/local/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1

How can I make this upgrade?

  • 3
    Are you very very sure you need to upgrade to 2.7.5? All bugfixes are being backported to 2.7.3 in Ubuntu. You really really want to save you all headaches with compiling from source. Please provide the specific reason for installing 2.7.5. On this site questions about a broken Python installation are daily business and it's very common to see it's being caused by installation from source. See for example askubuntu.com/q/323248/88802 – gertvdijk Aug 15 '13 at 20:48
  • 1
    I was using a package the wrong way but the question still stands and I really don't understand the downvote with no explanation given. – Gabriel Aug 15 '13 at 21:06
  • What happens when you run sudo make **install** instead of sudo make **altinstall**? Do you get the same error? – Kevin Bowen Aug 15 '13 at 21:43
  • Now I'm afraid of actually trying your solution since I've heard so many times it'll break my system. I'll mark your answer as accepted because it looks really complete though. Thank you. – Gabriel Aug 15 '13 at 22:50
  • 2
    @Gabriel The solution by maggotbrain is a very nice one; it allows you to install the version of your choice in a pyenv. No harm is done on your system's Python. I'll remember this for future questions. :) – gertvdijk Aug 19 '13 at 17:46

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://github.com/yyuu/pyenv.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
  • 1
    pyenv is brilliant for so many reasons. Helps me with my experimentation immensely with minimal hassle after the initial setup. – Fahad Yousuf Aug 26 '13 at 1:09
  • Is this going to be run from a specific user's home folder? How can I install this for every user? Can I install ./pyenv in /usr/local/bin or is that a bad idea? – biohazard Apr 11 '14 at 1:28

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.