22

How can I install extra versions of python on Debian (jessie). On Ubuntu I can use the "deadsnakes" PPA which will give me any python version I want, with the version name in the command (e.g. python33 for python 3.3). This allows me to install them all beside each other. I can use virtualenvs to install specific python packages for specific versions without messing with the system packages. I maintain some python libraries, and they need to work on many versions of python. If I have the python binary installed, then tox will take care of using virtualenvs for each python version.

So what's the debian equivalent of Ubuntu's deadsnakes PPA?

UPDATE I want to install python: 2.6, 2.7, 3.3, 3.4 and 3.5.

2
  • Can you specify which versions of Python you want installed? I think Jessie has a few different versions available. Commented Mar 7, 2015 at 10:07
  • In my opinion you are probably better off just installing various Python versions from source.
    – Celada
    Commented Mar 7, 2015 at 10:08

2 Answers 2

16

I would say there is no Debian equivalent to Ubuntu's deadsnakes PPA

Under Debian, using Ubuntu packages or repositories is not recommended. As this post appears in search engines, I propose here an answer that is less dangerous for a Debian system.

Installing Python manually is possible. As an example, you can use the following instructions to install 3.5.2 version

Prerequisites

Install dependencies :

sudo apt-get update && sudo apt-get install libssl-dev openssl

Building Python

You can build Python in a specific folder using the --prefix parameter from configure command:

wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar zxf Python-3.5.2.tgz
cd Python-3.5.2/
./configure --prefix=/usr/local
make
sudo make install

Instead of /usr/local, one can use another base directory. As an example:

sudo mkdir /opt/python-3.5.2
./configure --prefix=/opt/python-3.5.2

Selecting python version

Using PATH environment variable can help choosing the right python version to use. But one can also use symlinks:

sudo ln -s /opt/python-3.5.2/bin/python3.5 /usr/local/bin/python3
sudo ln -s /opt/python-3.5.2/bin/pip3.5 /usr/local/bin/pip3

Using -f option will allow you to replace existing symlinks


Note: For python 3.9.16 (possibly any +3.9 version) you also might need to install the library: libffi-dev so the dependencies would be:

sudo apt-get update && sudo apt-get install libssl-dev openssl libffi-dev
14

Using the PPA

You can use the PPA on Debian. Pick an Ubuntu version that's from slightly before your Debian version, and it should have all the necessary libraries. For wheezy, the oneiric PPA seems ok (but it lacks more recent Python versions). For jessie, the trusty PPA should work.

To add a PPA on Debian,

  1. Download and add the PPA signing key with:

    gpg --keyserver keyserver.ubuntu.com --recv-keys F23C5A6CF475977595C89F51BA6932366A755776
    gpg --export F23C5A6CF475977595C89F51BA6932366A755776 | sudo tee /usr/share/keyrings/ppa-deadsnakes.gpg > /dev/null
    
  2. Then create a file /etc/apt/sources.list.d/ppa-deadsnakes.list containing:

    deb [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty main 
    deb-src [signed-by=/usr/share/keyrings/ppa-deadsnakes.gpg] https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ trusty main 
    
  3. Finally run apt-get update and install the desired packages.

If you can't get the PPA working for some reasons (maybe you can't find a version that works with the libraries you have), you can download the source and recompile them for your distribution.

Using a chrooted system

What I usually do to test compatibility with other versions is to run older or newer distributions in a chrooted system. For example, you could install various versions of Ubuntu with the Python versions you're interested in, or you could install trusty in a chroot and install the PPA there. For more information, see my schroot guide.

2
  • 2
    You should avoid using Ubuntu PPAs on Debian, as it might cause issues or other conflicts. (It's also possible to use pyenv virtualenvironments for multiple Python versions) Commented Oct 7, 2017 at 14:33
  • I can confirm that I have successfully installed python 2.6, 2.7, 3.1, 3.2, 3.3, 3.5 and 3.6 on current debian testing using this approach. The only caveat I came across was that I needed to dig up an old version of libssl1.0.0 which I found here: packages.debian.org/jessie/libssl1.0.0 . I also used the xenial (16.04) versions of packages (current lts), though I believe trusty still works.
    – Att Righ
    Commented Dec 11, 2017 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .