dastoev.com

Install Python 3.7 on Raspberry Pi (Raspbian)

Currently the newest version that Raspbian incudes is 3.4 That means building from source.

Installing the dependencies needed to build

Some of the packages might be already installed on the system.

List of dependencies:

  • 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 update -y
sudo apt-get install 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 -y

Note: If one of the packages cannot be found, try newer version like libdb5.4-dev instead of libdb5.3-dev

Download source

When downloading the source code, select the most recent release available on the official site. You will have to adjust the file names accordingly.

Python-3.7.3

wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar xf Python-3.7.3.tar.xz; cd Python-3.7.3

Compile and install

Compiling takes some time especialy on older raspberry pi models, be patient :)

./configure
make
sudo make altinstall

Cleaning

Delete source

cd ..
sudo rm -r Python-3.7.3
rm Python-3.7.3.tar.xz

Optional. Uninstall the previously installed packages. When uninstalling the packages, make sure to only remove these that were not previously installed on your system.

sudo apt-get --purge remove build-essential tk-dev -y
sudo apt-get --purge remove libncurses5-dev libncursesw5-dev libreadline6-dev -y
sudo apt-get --purge remove libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev -y
sudo apt-get --purge remove libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
sudo apt-get autoremove -y
sudo apt-get clean