Raspbian Stretch 9 for Raspberry Pi includes Python 3.5. Here is how to compile Python 3.7 on the Raspberry Pi.
Compile Python interpreter
Note: in general, one of the few times you should ever use
sudo on a Linux computer is
- get prereqs on your ARM device:
apt install libffi-dev libbz2-dev liblzma-dev libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev libreadline-dev libssl-dev tk-dev build-essential libncursesw5-dev libc6-dev openssl git
- get the latest Python source code and extract.
- Configure (3 minutes on Raspberry Pi 2):
cd cpython-3.7* ./configure --prefix=$HOME/.local --enable-optimizations
- Build and install–this step takes 10-40 minutes, depending on Raspberry Pi model.
Do not use
make -j -l 4 make install
Note: don’t omit
-l 4or Pi will be quickly overwhelmed and error build. This limits load average to 4. Without it, load average will soar to 100+ (bad).
- add to
then open a new Terminal
which python3 and
which pip3 etc. refer to
~/.local/bin/ instead of
Don’t unnecessarily uninstall system Python 3
/usr/bin/python3 because system packages depend on it.
The PATH you set in Step 5 above makes Linux prefer your new Python 3.7.
Why upgrade to Python 3.6?
Python 3.6 represents a real milestone, as profound an improvement as Python 3.4 over Python 2.7.
pathlib: in Python ≥ 3.6 standard library
- inline variable “f-string” parsing.
typingtype hinting–detect bugs before they strike
Intel Edison: latest Python
Because the Intel Edison has a 32-bit x86 CPU, you can run Anaconda Python on the Intel Edison instead of compiling Python manually. Yes, Intel Edison actually has a 64-bit CPU, but most people use it with a 32-bit OS.