Step by Step Python 3.9.7 installation guide Raspberry Pi

Easy to follow step by step guide to install Python 3.9.7 on the Raspberry Pi. Now with simple Python installation one liner on Raspberry Pi.

Finally, you got a Raspberry Pi, and want to run your new written Python scripts on it.

Bummerrrr…. the Raspberry PI OS has an old Python version installed. So now what? Well very simple you upgrade it to 3.9.7 in a few easy steps.

I have already written about installing Python 3.9 on a Raspberry, but you are looking at the latest version right now. And I have even better news!

I was so tired of typing in the command shell lines I have written a script to install the latest 3.9.7 version in a matter of .. well one line!

Yes one simple line of code!

One line of SH to Rule them all!!

The last few weeks I have been working on a solution that everybody could use. A simple but effective Python for Raspberry Pi updaterrrrr. I one line of SH to rule them all!

And yes created a script. A script that updates the OS, installs the essential components, installs the newer python version (what ever version you choose) and sets the new version to the default version.

Few notes!

  • If you do not want to update your OS. DO NOT USE THIS!
  • There is no Warranty what so ever! If it breaks your system, well I’m not to blame.
  • Yes I dit test this. I tested it a couple of 20 times. It did not break anything, but I only tested it on on version of Raspberry OS and Ubuntu.
  • If it does not work for you, well there is no Warranty, but please let me know what went wrong so I can improve it!
  • You cannot install a lower version that is already installed on your Raspberry Pi or Ubuntu. That’s not how it works.
  • And last, but not least, I’ve put quite some time into this so please buy me a cup of coffee on my donation page! Thank you

Here’s the code for python 3.9.7


wget -O - https://raw.githubusercontent.com/tvdsluijs/raspberry-pi-python-sh-installer/main//python3.9.7.sh | sudo bash

Step by Step Python 3.9.7 on Raspberry Pi installation
You will see this when ready!

What is a Raspberry PI?

So, little recap! Raspberry Pi?

The Raspberry Pi is a little computer the size of a credit card. A Rasp is very cheap, for about $45 it’s yours. You can connect a monitor to it, with the 4+ even 2! And of course a keyboard and mouse. It has a network connection and 4 USB ports.

The small device is very powerful (for its size) and actually anyone can work with it. You can use it as a PC, server, firewall etc. With languages like Scratch and Python you can write very powerful programs.

Besides that it can do everything you expect from a PC, you surf around on the internet, you watch Netflix, YouTube or another HD video, you read your mail, make spreadsheets and work on your documents. And yes, you can play games on it too!

Raspberry Pi OS?

Raspberry Pi OS is a Linux distribution developed for educational purposes and optimized for the various models of the Raspberry Pi. Raspbian is a fork of Debian that can be installed as a live system on an SD card or a microSD card.

How ever!!! A Raspberry Pi and the Raspberry Pi OS are very powerfull! Yes it is great for educational purposes but it can also be used for various great business models. Like taking care of your Ubiquiti network, handling your email, be a great firewall, act like a NAS, get data from your smart energy meters, process data from your solar panel inverters, gard your house with AI camera footage… the possibilities are endless

Next to monitoring my network I also use it for a lot of my Python program’s.

Python 3.9.7

Python developed by Guido van Rossum in the early 1990s is a programming language. At that time he worked or was situated at the Center for Mathematics and Computer Science in Amsterdam. Yes in The Netherlands. Python is a ‘general-purpose’ programming language, which means that it can be used for almost anything.

Python is a programming language that is generally easy to read. This is why Python is so widely used. It’s easy to learn, you can read it and others can also read it easily. This makes it easier to maintain and you think better / more logically while programming. Python is widely used for scripting but can also be compiled into executable programs. I really love Python!!!

If you don’t want to install python 3.9.7 line for line… scroll up for the easy to use one line of code!!

Install Python 3.9.7 on a Raspberry Pi Using Source Code

First of all, update your Raspberry Pi. It’s always a good idea to keep it up to date. Due to fixed vulnerabilities, feature updates and general bug fixes

Open up your terminal on your raspberry pi and do a:

sudo apt update

Then install essential packages for compiling source code.

sudo apt install wget build-essential checkinstall

and

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

Download the Python 3.9.7 source code from the official site with this single command!

wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz

When fineshed downloading unpack the file with

tar -Jxf Python-3.9.7.tar.xz

Finished unpacking? Great, go to the folder the tar created by doing a

cd Python-3.9.7

Then prepare the source for the installation with

./configure --enable-optimizations --prefix=/usr

Now do a

make

to compile the source, it’s a good time to get a coffee and a good book. This will take a while!

Ready? Do a

sudo make altinstall

this replaces your previous Python installation!!

It’s always good to cleanup after yourself by doing

cd ..
sudo rm -r Python-3.9.7
rm -rf Python-3.9.7.tar.xz

Now… The moment of truth!

Do a

Python --version

ahhhh bummerrrrrrr, you see this?

> Python 2.7.x

Don’t worry, I have your back!!

Finishing up Python 3.9.7 on a Raspberry Pi

Do this in your terminal

update-alternatives --install /usr/bin/python python /usr/bin/python3.9

Than do:

python -V
> Python 3.9.7

All done!

Did you find this article valuable?

Support Theo van der Sluijs by becoming a sponsor. Any amount is appreciated!