Of course, you need a Raspberry Pi with a running Raspbian. I have tested this instructions on a Raspi 1 B+ and Raspbian Stretch (Image from 2019-04-08). I think, any newer hard/software will work too.
Because there isn't any package for Python 3.7 on armhf (=Architecture of the Raspi), we have to compile Python from sources. This takes a while, but you can leave it completely unattended.
- Go to https://www.python.org/downloads/source/ and take the newest Release (at the time of writing, its 3.7.3).
- Download it with wget:
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
- Uncompress it with tar:
tar -xf Python-3.7.3.tar.xz
- Jump in that folder with cd:
cd Python-3.7.3
To compile Python, we need some additional packages:
sudo apt-get install libncurses-dev libreadline-dev tk-dev libsqlite3-dev sqlite3 libgdbm-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev build-essential libncurses5-dev libgdbm-dev libffi-dev libncursesw5-dev libnss3-dev
Now we have to decide where we want to install Python. I recommend to install it in /usr/local/opt/python3.7
so you don't touch the preinstalled Python3. This is important, because some administrative tools won't work with Python 3.7.
So run:
./configure --prefix=/usr/local/opt/python3.7
This step generates the makefile based on the system configuration.
Now we can run the make command. The option -j 4
tells the compiler that he should use all 4 cores. You can omitt that if your Raspi only has one core.
make -j 4
When the build has finished, we have to run:
sudo make altinstall
To copy all the files to the prefix we have specified.
To run Python everywhere, we need to add /usr/local/opt/python3.7/bin
to the PATH environment variable. In order to do that, start
nano /etc/profile
and append the following line at the bottom:
PATH=$PATH:/usr/local/opt/python3.7/bin
If everything worked, you can run python3.7
and the interactive shell should start.
Have fun!