I have a Raspberry pi 3 running on Raspbian 8, and I was trying to run python 3.7 for a specific application that will run on it. The python 3.7 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.7.
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
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
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.7.4/Python-3.7.4.tgz | tar xz cd Python-3.7.4/ ./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.7 command and try ‘import ssl’, if you haven’t any errors, you’re done!