How to use Latest Python 2.7.x "The Right Way" on Ubuntu 12.04 LTS?

41,869

Solution 1

EDIT: *As @Anthon has pointed out in the comments, this PPA does not include Python 2.7 for Ubuntu 12.04 (Precise). See funky-future's answer below, which I don't believe existed when I originally responded.

The preferred "Ubuntu" way to deal with packages not included in their universe by default is to use a PPA (third party repository), rather than manually compiling. You maintain the benefits of package management, updates, and dependency resolution this way.

However, the third party repositories are NOT officially supported, if that is part of your requirement.

The DeadSnakes (get it) PPA maintains Python releases not included in the systems package management.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7

You can read more about this PPA here.

However, in your case this does not include Python 2.7, as DeadSnakes only provides major versions not included and not point releases. As Ubuntu already packages 2.7 for Ubuntu 12.04, DeadSnakes will not provide this.

It might be preferable for you to make the case that you should not use the native packaging with Ubuntu in this case. See this excerpt from DeadSnakes;

Using third-party modules packaged for Debian or Ubuntu with the Python
interpreters from this repository is a bit of a mixed bag. For Python 2, Python
modules from the official repositories will not work, as a consequence of how
Python packaging works in Debian. For Python 3 on the other hand, all
pure-Python module packages at least should be available; compiled extension
modules will not work however.

In general, you're better off installing Python modules using the common Python
packaging tools rather than the system package manager. For an introduction into
the Python packaging ecosystem and its tools, refer to;
    http://guide.python-distribute.org/

A few of these tools might also be provided in this repository as a convenience.

If you are absolutely required to use the operating systems package management, and are unable to move to a different version of Ubuntu with a package provided by DeadSnakes, or natively, than you only have two options left, as I see it.

  1. You could request a backport of Python 2.7.5 to Ubuntu 12.04.
  2. You could create your own PPA with the version of Python you require.

side note: AskUbuntu is a better StackExchange to post stuff like this to, than SuperUser generally.

Solution 2

Felix Krull also maintained (as in unmaintained now) a PPA with the latest Python 2.7 release for Ubuntu Precise, Trusty and Utopic. You can use the same process like krondor describes, but use instead or additionaly this PPA: ppa:fkrull/deadsnakes-python2.7.

sudo add-apt-repository ppa:fkrull/deadsnakes-python2.7
sudo apt-get update
sudo apt-get install python2.7
Share:
41,869

Related videos on Youtube

Will
Author by

Will

Software and Infrastructure Architect; specializing in Python, PHP, Java, Shell Scripting, Linux/UNIX administration, Scientific Computing and Big Data, Scaling, High-Availability, and Security, among others.

Updated on September 18, 2022

Comments

  • Will
    Will over 1 year

    My project needs to stay current on Python releases, but 12.04LTS is currently stuck on 2.7.3, even though 2.7.5 is out now. Is there a way I can stay more current without manually compiling? We're required to stay on package-based installation for Python. What's the "right" way to handle this?

    Thanks!

  • krondor
    krondor almost 11 years
    Yes, it does seem to be popular and well maintained. I'd have little reservation using it.
  • krondor
    krondor almost 11 years
    @Anthon you are correct, I didn't notice that. DeadSnakes will not replace a major release, so since Ubuntu already bundles Python 2.7, Deadsnakes will not provide point releases for that series. Rather they provide 3.3 for Precise. This will not help the OP in this case.
  • cr8ivecodesmith
    cr8ivecodesmith over 8 years
    This should be the accepted answer.
  • mivk
    mivk over 7 years
    It has a "discontinued" warning now, but works nicely for machines which still run older Ubuntu versions. The PPA provides versions 2.7.12-1~precise1, 2.7.12-1~trusty1 and 2.7.10-0+utopic1 (for 12.04, 14.04 and 14.10).
  • socrates
    socrates over 7 years
    Just note that frull/deadsnakes-python2.7 ppa is discontinued. For the latest Python 2.7 releases(like 2.7.13), try use jonathonf/python-2.7 ppa.
  • dermen
    dermen about 7 years
    warning - this caused problems for me when upgrading distributions (12 -> 14).. I was left with a truly dead python.. Be sure to undo this ppa before upgrading..
  • funky-future
    funky-future about 7 years
    well, that's true for any distribution update and ppas.
  • Truggi
    Truggi about 7 years
    On 14.04 I had to use ppa:fkrull/deadsnakes-python2.7 (note the suffix)
  • tyleha
    tyleha almost 7 years
    It appears this ppa is now dead. I haven't found a replacement and instead just downloaded and built the source myself from python.org/downloads