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:

[debugger]
apt list –installed
sudo apt-get autoremove python*
[/debugger]

Ensure system is up to date:

[debugger]
sudo apt-get update
[/debugger]

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

[debugger]
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
[/debugger]

Get the python src distribution:

[debugger]
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
[/debugger]

Configure and compile (this might take an awful lot of time, depdning on your Raspberry’s performances):

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

Install:

[debugger]
sudo make altinstall
[/debugger]

Make aliases and default version:

[debugger]
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
[/debugger]

Check proper installation:

[debugger]
python -V
[/debugger]

Comments

Leave a Reply

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