How to install 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 (takes a while!)
tar xf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure --prefix=/usr/local/opt/python-3.7.0
make -j 4

sudo make altinstall

Make Python 3.7 the default version, make aliases
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
alias python='/usr/bin/python3.7'
alias python3='/usr/bin/python3.7'
ls /usr/bin/python*
cd ..
sudo rm -r Python-3.7.0
rm Python-3.7.0.tar.xz
. ~/.bashrc

And verify:
python -V

And if you want to revert:
update-alternatives --config python

19 thoughts on “How to install 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?


      1. I am getting the same error… but haven’t been able to fix it yet. I followed the instructions in the stackoverflow page too…

  2. When I try to make py 3 my default I put I get the following error message: ln: failed to create symbolic link ‘/usr/bin/pydoc3.7’: File exists

    Everything worked fine up until this point… I can’t seem to make py 3 my default.

  3. Thanks for the instructions.
    The worked fine except for
    sudo rm -r Python-3.7.0
    rm Python-3.7.0.tar.xz
    because at that point of the sequence, the current location is Python-3.7.0, so a simple
    cd ..
    should probably be added.

    Making the aliases works, too, but they don’t “stick”, i.e. after rebooting
    $ python3
    will invoke python 3.5.4 again.
    I have added
    @reboot alias python3=’/usr/bin/python3.7′
    to crontab, but to now avail (although the line is executed)
    Any ideas? (sorry., I’m pretty much a newbie to Linux/Raspian)
    TIA, Beat

      1. and so? I just spent 2 days getting 3.7.0 installed from your great instructions – thank you. Your last line (added?) has typo? you say verify it with python -V I think you mean python3 -V? I did, it came back 3.7. reboot and now it comes back with 3.5 again.

        I am super newbie and no clue. does this need fixed?

        thank you.

  4. Can you simply do:
    alias python3=’/usr/local/opt/python-3.7.0/bin/python3.7′

    since that’s where you installed to? Then when you do “python3 -V” it outputs 3.7.0 properly.

  5. raspbian stretch doesn’t know where to get libffi_dev so python install failes:
    Failed to build these modules:
    `E: Unable to locate package libffi_dev`

  6. worked fine on my pi3. Thanks for the great write up! also, the output from python -V echos python 3.7.0 .

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.