Update Python

Here is the procedure to follow to update python to a given version on a Raspberry Pi.

First go to the official Python website to check which is the latest version. Then download it as follows:

wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz

(Note: replace 3.9.9 by the relevant latest version value)

Uncompress the file downloaded:

tar -zxvf Python-3.9.9.tgz

then change directory

cd Python-3.9.9

Apply the following command to configure Python:

./configure --enable-optimizations

The run the following command:

sudo make altinstall

This above command will take a long, long,…time to complete. Once done, we need to remove the previous version of Python (rm) and replace it by the new one (link ln). The Python files are stored in the /usr/bin directory.

cd /usr/bin

sudo rm python (this is a link to the directory /usr/local/bin/python_previous_version)

ln -s /usr/local/bin/python3.9 python 

You can check the current version with the command:

python --version