Running older Python 3 versions on Ubuntu 22.04

2022-05-02 11:00

Just updated to Ubuntu 22.04 which has Python 3.10 as default version but I need to be able to run other versions for various projects. Just trying to install older versions tells me the packages are not available.

To resolve this I installed the deadsnake PPA and then the desired version of Python:

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python3.7

Then I can just initialize my virtualenv with correct Python version:

$ python3.7 -m venv venv

Now, I had an additional problem with pyenv in some project where I was using that. Turns out the default Ubuntu package for pyenv is very old so I resorted to removing the system version and installing the latest locally for my user using pip.

$ sudo apt remove pipenv
$ pip install pipenv

Remember to add $HOME/.local/bin to the PATH.

Now I have my system setup in a way that allows me to create isolated environments for all my Python projects no matter the version they require.