How to upgrade Python on Raspberry Pi?

Raspberry Pi ships with a bit old version of Python – 3.9. What to do, if you want to upgrade to the newer version? The only way is to download sources and compile ’em.

In my case, I want to upgrade to Python 3.10.

Let’s try:

# Upgrade the system, just in case
$ sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade -y

# Remove current version of Python
$ sudo apt-get remove python3 --purge
$ sudo apt autoremove -y

# Install Python 3.10
$ wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
$ tar -xzvf Python-3.10.9.tgz
$ cd Python-3.10.9/
$ ./configure --enable-optimizations
$ sudo make altinstall

# Check if installed
$ /usr/local/bin/python3.10 -V

# Make Python 3.10 the new, default Python
$ sudo ln -s /usr/local/bin/python3.10 /usr/bin/python

# Let's try
$ python -V

# Install pip
# Install pip
$ python -m ensurepip --upgrade
$ sudo ln -s /usr/local/bin/pip3.10 /usr/bin/pip
$ sudo ln -s /usr/local/bin/pip3.10 /usr/bin/pip3

My advice – be patient. It takes time on Raspberry Pi to compile Python from sources.

Be First to Comment

Leave a Reply

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