Raspberry Pi

How to Update Python on Raspberry Pi

Python and Raspberry Pi OS are made for each other, as without Python, you will face issues while accessing your Raspberry Pi terminal or running other applications that require Python. There are other advantages of having Python on Raspberry Pi as well, such as ease of use, versatility, and freedom to access several Python libraries that are included in the Raspberry Pi libraries list.

Since replacing the older Python version with the new one is a complex task because you won’t be able to remove the previous Python version as it will result in system failure. So, to help you out in this situation, we present this article to provide your guidelines on how you can update Python on Raspberry Pi.

How to Update Python on Raspberry Pi

To update the Python version on Raspberry Pi, you must need to follow the step-by-step instruction given below:

Step 1: Install Python on Raspberry Pi

First, head toward the official Python website to check the latest version of Python. At the time of writing, the latest version of Python is 3.9.9; thus, we have used the following command to install this version on Raspberry Pi.

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

 

Step 2: Extract File Contents

Next, you must extract the contents of the Python-3.9.9.tgz file using the following command:

$ tar -zxvf Python-3.9.9.tgz

 
The above command will store the file in a directory with the name “Python-3.9.9”.

Step 3: Configure Python Latest Version on Raspberry Pi

After successfully extracting the contents, it’s now time to configure Python on Raspberry Pi and for this purpose, head towards the Python directory using the following command:

$ cd Python-3.9.9

 

Next, apply the following command to configure Python on Raspberry Pi:

$ ./configure --enable-optimizations

 

After the configuration, run the following command to build the installation packages for the latest version of Python on Raspberry Pi:

$ sudo make altinstall

 

Step 4: Update the Python Version on Raspberry Pi

To make the latest version of Python the default one, you must need to remove the previous Python version and replace it with the new one.

Since the Python files are stored inside the directory “/usr/bin”, you must need to visit the directory using the following command:

$ cd /usr/bin

 

At the current location, remove the previous Python directory using the following command:

$ sudo rm python

 

Next, link the latest version of Python placed inside the directory “usr/local/bin” using the following command:

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

 

This will update the Python version on your Raspberry Pi device and you can confirm it by executing the following command:

$ python --version

 

Conclusion

Updating the Python will help you speed up your system and application’s performance because the newer version comes with new features compared to the previous version. Now that you have learned how to update the Python version on Raspberry Pi through the above guidelines, it’s time to take out your Raspberry Pi device, open the terminal and perform the step-by-step instructions mentioned above to update the Python version successfully.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.