How to downgrade Python version to 3.8 in Ubuntu 22.04?

Posted under » Ubuntu » Python » Django on 1 Aug 2022

If you use Django it is best that you use Python ver 3.8 because it supports more Python libraries than the latest version of Python (3.10). Python 3.8 supports Django version 3.1, 3.2, 4.0 and 4.1. Meanwhile Python 3.10 only supports Django 4 version.

Do not downgrade the system version: it's likely that some parts of the system would stop working. Never change /usr/bin/python3, and avoid putting an older version of python3 before it in the $PATH.

What you need to do is add another version of Python to the one that exist in 22.04, which is 3.10. Let's say you want to add an older version (LTS 20.04 is 3.8).

The deadsnakes archive provides packages of most supported Python versions for currently supported Ubuntu LTS versions. To make these packages available, follow the usual instructions to enable a PPA. Then install the package(s) you want.

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.8

Different versions of Python can co-exist. To check if the version was indeed installed.

$ python3.8 -V

You can then create a virtual environment for your chosen Python version and with a chosen set of packages.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT