Installing Python 3.7 on Raspberry Pi

This short guide explains how to install Python version 3.7.0 on a Raspberry Pi running Raspbian aswell as other Debian based Linux distributions including Ubuntu.

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 and install
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar xf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure --prefix=/usr/local/opt/python-3.7.0

make
sudo make install

Make Python 3.7 the default version
sudo ln -s /usr/local/opt/python-3.7.0/bin/pydoc3.7 /usr/bin/pydoc3.7
sudo ln -s /usr/local/opt/python-3.7.0/bin/python3.7 /usr/bin/python3.7
sudo ln -s /usr/local/opt/python-3.7.0/bin/python3.7m /usr/bin/python3.7m
sudo ln -s /usr/local/opt/python-3.7.0/bin/pyvenv-3.7 /usr/bin/pyvenv-3.7
sudo ln -s /usr/local/opt/python-3.7.0/bin/pip3.7 /usr/bin/pip3.7

Cleanup afterwards:
sudo rm -r Python-3.7.0
rm Python-3.7.0.tar.xz

And verify:

python -V

This should return 3.7.0

8 thoughts on “Installing Python 3.7 on Raspberry Pi”

      1. tested on rpi2b+ and installs ok, but does not become default python3
        what do i need to do to make python3.7 default
        using your amended script, rpi still thinks python is version 3.5.4

  1. Following these directions I’m getting errors with pip

    “pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.”

    I made sure to install the dependencies listed, could there be something else that is missing?

    Thanks

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.