How to install Python 3.9.4 on Raspberry Pi

This short guide explains how to install Python 3.9.4 on a Raspberry Pi running Raspbian.

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 (takes a while!)
tar xf Python-3.9.4.tar.xz
cd Python-3.9.4
./configure --prefix=/usr/bin/python3.9.4
make -j 4

sudo make altinstall

And remove the files

cd ..
rm -r Python-3.9.4
rm Python-3.9.4.tar.xz

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

And verify:
python -V

Leave a Reply

Your email address will not be published. Required fields are marked *