Install Different Python3 Versions

2 minute read

Background/Problem

Every Linux distribution I have used so far ((K)Ubuntu, Arch) ships with its own version of Python3 in its package repositories. While this is perfectly fine most of the time, I ended up in situations where I needed a specific version of Python3 that differed from the version that was in the repositories of the distribution I used at the time.

While it’s actually not that complicated to install an additional version of Python3, somehow I still always have to look up, how it works. So I figured I should just write it down.

Solution

How to install additional versions of Python3 depends a little bit on the distribution you’re on. Therefore the two subsections.

(K)Ubuntu

In (K)Ubuntu you can easily install additional Python3 version from source. In order to do so some requirements (in terms of installed packages) have to be met. If you haven’t already done so, use the following comments to install some needed packages:

sudo apt-get install build-essential checkinstall tk-dev
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

Then download the python source for the version you want to install from the python website [1] and unpack it into an arbitrary folder (for example on the desktop).

cd into the folder and run the following commands:

sudo ./configure --enable-optimizations
sudo make altinstall

That should be it. If you want, you can delete the folder you unpacked the source code into, if you want now.

The Python3 version of the distribution should still be there and the command ‘python3’ should still point to that version. But additionally you should be able to run for example ‘python3.5’ now.

Arch Linux

On Arch you can install additional Python3 version from the AUR. On the AUR Homepage [2] search for the version you would like to install, e.g. “python35” for Python version 3.5. Follow the link to the package and copy the “Git Clone URL” in the “Package Details” section.

cd into an arbitrary folder (e.g your desktop or download folder might be a good choice) and run:

git clone <GIT_CLONE_URL>

cd into the folder that git cloned the package into. If you don’t trust the people that created the package, you should check the files in this directory before you proceed.

Then run:

makepkg -si

During the installation process you will probably be asked for your password. I think you have to have root privileges to install additional python versions.

This should be it. If you want, you can delete the folder git cloned the package into now.

The Python3 version of the distribution should still be there and the command ‘python3’ should still point to that version. But additionally you should be able to run for this example ‘python3.5’ now.

Change Log

2022-09-12:

  • Change wording a little bit.
  • Fix some typos.



Take care,
Andreas


References

  1. Python Software Foundation, “Python Source Releases.” [Online]. Available at: https://www.python.org/downloads/source/. [Accessed: 13-Dec-2020].
  2. aurweb Development Team, “AUR Home.” [Online]. Available at: https://aur.archlinux.org/. [Accessed: 13-Dec-2020].

Updated:

Leave a comment