Install Python 3.8 on a Raspberry pi with Raspbian 8

Install Python 3.8 on a Raspberry pi with Raspbian 8

Last updated: 2020-05-27 By Timothé Mermet-Buffet

I have a Raspberry pi 3 running on Raspbian 8, and I was trying to run python 3.8 for a specific application that will run on it. The python 3.8 is not available in the repository, so I had to compile it myself.

Unfortunately, it wasn’t that easy to get it running, and I ran into that problem:

Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

It seems the LibreSSL doesn’t provide the necessary APIs used by Python 3.8.

Fixing

First, ensure the build tools are installed:

sudo apt-get install build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

Installing OpenSSL

We need to download and compile the latest version of OpenSSL, check the version number to take the latest one on: https://www.openssl.org/source/

cd /usr/src
curl https://www.openssl.org/source/openssl-1.1.1c.tar.gz | tar xz
cd openssl-1.1.1c/
./config shared --prefix=/usr/local/
make -j 4
sudo make install

Installing Python

To be able to compile Python using the OpenSSL version we just installed, we will need to add to the dynamic library loader the path to the /usr/local folder libs by setting the environment variables LDFLAGS, LD_LIBRARY_PATH and CPPFLAGS for the compiler.

export LDFLAGS="-L/usr/local/lib/"
export LD_LIBRARY_PATH="/usr/local/lib/"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/openssl"

We need to download and compile the latest version of Python, check the version number to take the latest one on: https://www.python.org/ftp/python/

cd /usr/src
curl https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz | tar xz
cd Python-3.8.2/
./configure --enable-optimizations --with-openssl=/usr/src/openssl-1.1.1c
make -j 4
sudo su
export LDFLAGS="-L/usr/local/lib/"
export LD_LIBRARY_PATH="/usr/local/lib/"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/openssl"
make altinstall

I had to tell again the position of the libraries before doing the make altinstall.

After that, run the python3.8 command and try ‘import ssl’, if you haven’t any errors, you’re done!

About the author

Timothé Mermet-Buffet

I'm a software engineer passionate about computer sciences. I love to learn and experiment with new innovations in electronics, machine learning, and distributed systems. Oh, and by the way I'm also the CEO of AlienGen, a software agency with people as crazy as me!

Want help on a similar project ?

Thanks for getting in touch!

Oops! Something went wrong.