Update! 30 Sept 2021
So I’ve bought a new Raspberry Pi, the 4+ to be exact. I’ve put 32GB micro SDcard in it, installed Raspberry Pi OS on it, did my ssh stuff and Yes! I’ve upgraded to Python 3.9.5!
I have written about installing Python 3.8 and Python 3.9 on a Raspberry, but you are looking at the latest version right now.
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 is a programming language designed and developed in the early 1990s by Guido van Rossum, at the time affiliated with the Center for Mathematics and Computer Science in Amsterdam. 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. Python is also an HLL or High Level Programming language. This is why Python is so widely used. 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.
Install Python 3.9.5 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
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
Download the Python 3.9.5 source code from the official download site with this command!
When fineshed downloading unpack the file with
tar -Jxf Python-3.9.5.tar.xz
Finished unpacking? Great, go to the folder the tar created by doing a
Then prepare the source for the installation with
./configure --enable-optimizations --prefix=/usr
Now do a
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 install
this replaces your previous Python installation!!
It’s always good to cleanup after yourself by doing
cd .. sudo rm -r Python-3.9.5 rm -rf Python-3.9.5.tar.xz
Now… The moment of truth!
ahhhh bummerrrrrrr, you see this?
Don’t worry, there are two options!
- you leave it like it is and in your Virtual environment (Venv) you point to Python 3.9.5
- we do some extra magic and make 3.9.5 the default!
Let’s do 2!
Finishing up Python 3.9.5 on a Raspberry Pi
Do this in your terminal
echo "alias python='/usr/local/bin/python3.9'" >> ~/.bashrc
Then do a
Or close your terminal and reopen the connection to your rasp in a new terminal