Debian – Install newer & older versions of python on debian

debianpython

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.

Best Answer

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, create a file /etc/apt/sources.list.d/deadsnakes.list containing

deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main 
deb-src http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main 

Download the PPA signing key with

gpg --keyserver keyserver.ubuntu.com --recv-keys DB82666C

then add the key to the APT key database with

gpg --export DB82666C | sudo apt-key add -

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.

Related Question