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.
First, get rid of old versions:

apt list –installed
sudo apt-get autoremove python*

Ensure system is up to date:

sudo apt-get update

Install the dependencies needed for building the distribution:

  • 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
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

Get the python src distribution:

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 and compile (this might take an awful lot of time, depdning on your Raspberry’s performances):

./configure –prefix=/usr/local/opt/python-3.7.0
make -j 4

Install:

sudo make altinstall

Make aliases and 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
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

Check proper installation:

python -V
Filed in Blog, Python. Bookmark the permalink.

Leave a Reply

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