How to install Python 3.8 on Raspberry Pi

This short guide explains how to install Python version 3.8.0 on a Raspberry Pi running Raspbian.
This post is an update to How to install Python 3.7 on Raspberry Pi

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.8.0.tar.xz
cd Python-3.8.0
./configure --prefix=/usr/local/opt/python-3.8.0
make -j 4

sudo make altinstall

And remove the files

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

Make Python 3.8 the default version, make aliases
sudo update-alternatives --config python

And verify:
python -V

16 thoughts on “How to install Python 3.8 on Raspberry Pi

  1. Hi

    All good up to sudo update-alternatives –config python which give me an error message “no alternatives for python”

    File python3.8.0 is currently located in /usr/local/opt/ I cannot run it by typing python3.8.0 in the above location. Typing python3 executes an earlier version.

  2. Same problem as Nigel Cornes on 21DEC2019. All good up to sudo update-alternatives –config python which gives me an error message “update-alternatives: no alternatives for python”

    And, yes, typing python3 at command prompt produces:

    Python 3.7.3 (default, Apr 3 2019, 05:39:12)
    [GCC 8.2.0] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.

    Any assistance on this error will be gratefully received! Thanks.

  3. Hello all,
    @Ramon van Belzen: Thank you very much for the How to!

    I have the same problems as Nigel Cornes and Mikeinnc.
    I followed your How to step by step (except the fact that i used the python 3.8.1).

    The error message “no alternatives for python” means that there are no entries in an alternatives table.

    I solved the problem without using “sudo update-alternatives –config python” by adding the following lines to my bashrc
    nano ~/.bashrc
    export PATH=/usr/local/opt/python-3.8.1/bin/:$PATH
    alias python=’/usr/local/opt/python-3.8.1/bin//python3.8′
    alias python3=’/usr/local/opt/python-3.8.1/bin//python3.8′

    after that you can reconnect to the PI or type “source ~/.bashrc”.
    Thats all.
    Hope that helps…

  4. Hi everyone,
    I got the same error “update-alternatives: error: no alternatives for python”.

    I also tried Sebastians’ suggestion but it couldn’t find file or directory. The ‘ marks copied over wrong. Replacing them with ‘ in nano fixed it. Thanks @Ramon and @Sebastian

  5. No update allternatives for python are actually present.
    python – by default runs python2.7
    python3 runs python 3.5

    Create your update alternatives as follows.

    `sudo update-alternatives –install /usr/bin/python python /usr/bin/python2.7 5`
    ‘ sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.5 6’
    ‘sudo update-alternatives –install /usr/bin/python python /usr/local/opt/python-3.8.0/bin/python3.8 4`

    you can also just do python3

    ‘ sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.5 6’
    ‘sudo update-alternatives –install /usr/bin/python3 python3 /usr/local/opt/python-3.8.0/bin/python3.8 4`

    Once you have run these you can use
    `sudo update-alternatives –config python3` to select the default

  6. After figuring out the double hyphen trick it works until I type python at the $ prompt when bash responds:
    bash: /pi/python3.8.2: no such file or directory ?

Leave a Reply

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