Install Python 3.8 on a Raspberry Pi

Install python 3.8 on a Raspberry Pi is very easy. You need just need to follow this easy guide and have Pyghon ready within minutes on your Raspberry Pi.

Update! 30 Sept 2021

I’ve written several Python installation articles about installing Python 3.9, Python 3.9.5 and Python 3.9.7. But if you really want to go the easy way, go to my Ultimate Python installation script!

So this will be a very short post on how to install Python 3.8 on a Raspberry Pi. You can actually build great things with python on a Raspberry, like my Smart Meter reader with P1 cable and Python.

The Raspberry Pi OS is the Foundation’s official supported operating system and comes pre-installed with 2 versions of Python. Last time I checked 2.7.x and 3.5.x. If you want to develop in Python 3 (and YES you want to develop in version 3), you need to specify the version of Python you are using each time and that is annoying! So, lets install the 3.8 version and make it your default!

Python 3.8

Python is a very powerful but easy to learn programming language. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.

Python has very efficient high-level data structures and a simple but yet effective approach to (OOP) object-oriented programming.

Python’s design philosophy is based on code readability with its notable use of significant indentation, trust me… that works great!.

Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms like windows, macOS, linux.

Install Python 3.8 on Raspberry PI

First make sure you can ssh to your Raspberry Pi. The default SSH user and password on Raspberry Pi OS are:
– login: pi
– password: raspberry

You cannot login to your Raspberry Pi with SSH? Read this!

First install the dependencies needed to build:

sudo apt-get update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev

Compile (yes… it takes a while, grab a coffee and get me one to!!)

wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
tar xf Python-3.8.0.tar.xz
cd Python-3.8.0
./configure --enable-optimizations --prefix=/usr
make

Let’s install what was compiled!

sudo make altinstall

And remove the files you don’t need anymore

cd ..
sudo rm -r Python-3.8.0
rm Python-3.8.0.tar.xz
. ~/.bashrc

And yes!!! Let’s make Python 3.8 the default version, make aliases

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1

And verify:

python -V

Your are ready to go!

Happy programming!!

Did you find this article valuable?

Support itheo.tech, I automate Sh!t by becoming a sponsor. Any amount is appreciated!