Watch the video:
Why run different Python versions
Why install a 64-bit Raspberry Pi OS? Same reason. Everyone has their own wants and needs, and so do some bits of software. You may need to update Python to get compatible packages installed, or downgrade to get older projects working. This guide shows you how.
Updating your Pi
The first thing to do is make sure your Pi is up to date.
|
|
and optionally
|
|
Installing required packages
A few other programs and packages are needed to make sure the installation goes smoothly.
|
|
Downloading Python
We need to download the Python source, build and then install it. To download Python, check the official python.org/downloads/ page to see what versions are available. We will need to remember a version number.
I have version 3.11.1 available, so I’ll download and install that.
|
|
Just replace VERSION
with 3.11.1
, or whatever version you’re looking to install. It appears twice (2 times) in the above command.
We are working in the Downloads folder just to keep your drive clean. You can delete the .tgz
and source files later once the installation is complete.
Building Python
Extract the Python source files:
|
|
Once again replace VERSION
with 3.11.1
, or your required version.
Then navigate into the new folder and configure the source files for building:
|
|
Now comes the building section. This can take some time. We can halve, or even further improve build time by telling it to use more cores. We can see how many cores our Pi has by running lscpu
. I have 4 cores in my Raspberry Pi 4.
Run
|
|
4
is the number of cores. If yours freezes later, stop it using Ctrl+C
and run it with just 2
cores.
If you’re fine with it building source files slow as molasses, just skip the -j
part entirely, and run only sudo make
.
Even though it may look frozen, it may just be taking a long time to process.
Optional: Monitor using HTOP
If you’re worried about it getting stuck, you can entertain yourself by monitoring the CPU usage stats for your pi. HTOP is a simple tool that we can use here.
Open a new terminal and run sudo apt install htop
, then htop
to bring up a nice GUI.
Installing Python
Finally, once the build process is complete (This can take half an hour or so), we can install Python.
Run
|
|
Finally, once it’s complete, run python3.11 -V
(or whatever version you’re using. Skip the minor number after the second dot if there is one).
You should now see your new Python installation running properly.
Just make sure to precede commands with python3.11
, or your version, otherwise, you may be using a different python version that’s installed, such as the default one.
Optional (and only if you know what you’re doing)
If you know what you’re doing, we can tell Raspberry Pi OS what version of python to use.
This may mess with things, so instead, you should just use python3.11
, or whatever version, as that will allow everything else to run happily as it is now.
|
|
Just remove the #
before the command. This is so people don’t copy/paste without reading. Obviously, you will also need to replace 3.121
with your version, ignoring the minor version again.
Now, running just python -V
should return your new, preferred Python version.