Upgrade Python on Debian

As you may know, Debian repositories update very slowly. At the time of writing, Python release versions are at 2.7.12 and 3.5.2, but in Debian 8 repositories you can find only 2.7.9 and 3.4.2. On Debian 7, versions in the repository are even older (2.7.3 and 3.2.3), both shipped in 2012.

This tutorial teaches you how to build Python from source and install the latest version. I assume you are using Debian 7 or 8. We will be obtaining the source code from the official Python FTP.

First, let’s check your currently installed version of Python. Run this command on your terminal:

python --version

You will see something like this:

Python 2.7.9

Commands below must be performed by the root user.

Obtain Python source code

The following commands will load an archive with Python sources for version 2.7.12 to the home directory, unpack it, and switch to the directory with unpacked files:

cd /homewget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xztar xf Python-2.7.12.tar.xzcd ./Python-2.7.12

Pay attention to the name of the folder with unpacked files. It will be the same as the archive name (without the archive extension).

Compile Python

Now we can build the updated Python binaries:

./configuremakemake install

Switch to the new version

If you check the Python version now, you still see the same old one. So we need to point the default Python interpreter path to the new python binary, which was installed to /usr/local/bin/python.

update-alternatives --install /usr/bin/python python /usr/local/bin/python 10

Now you will see the installed version:

python --versionPython 2.7.12

Differences for Python 3

Python 3 can be updated in the same fashion, with one simple difference – you need to specify python3 instead of python. Note that Python 3 doesn’t come pre-installed on Debian 7.

Check version:

python3 --version

Switch to new version:

update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3 10

When updating Python 3, remember to choose a corresponding archive from the Python FTP site.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.