This is due to Debian 9
using OpenSSL 1.1.0
., However, OpenSSL 1.1.0
support in the SSL module was only added to Python 2.7.13
, 3.5.3
and 3.6+
Thus, it makes the python under those versions cannot be correctly linked to ssl
library. Issues https://github.com/pyenv/pyenv/issues/945
So you have to manually add those libraries when you are compiling them.
My suggestion
Since your system is already compiled with the default python, unintentionally compiled different version of python into global
executable may cause many hidden problems, especially some commands used behind on system-default python.
So why not you use pyenv
, to control those version of pythons? pyenv
is like a python-version control programs, it uses shims
, through a process called rehashing, pyenv
maintains shims
in that directory to match every Python command across every installed version of python
, pip
, and so on.
For more documents, please reading: https://github.com/pyenv/pyenv.
To install pyenv
, please following the provided reference.
Solution
After many hours struggling, I finally found a solution to perfectly solve those version of pythons confliction problems, copy and paste the following script to a new file, and make it executable, then you can compile and install those pythons. While if you want to install them in other way, say, without using pyenv
, please change the last second line commands to fit your needs.
#!/bin/bash -e
# Note: it is a script to solve Ubuntu 18.04 LTS
# different version of pythons compiling
# header confliction problems
#
# The idea is got from @JustAnotherArivist
# From URL: https://github.com/pyenv/pyenv/issues/945
#
# The script used in here is with slightly modifications
# to fit many different SSL header versions
# First under your home directory make OpenSSL library
# and extract useful package
mkdir ~/libssl1.0-dev
cd ~/libssl1.0-dev
apt-get download libssl1.0-dev
ar x libssl1.0-dev* data.tar.xz
tar -xf data.tar.xz --strip-components=2
# Second, specifically get your current system's SSL headers
# and make symbolic-links
libcrypto=$(ls /usr/lib/x86_64-linux-gnu/ | grep libcrypto.so......)
libssl=$(ls /usr/lib/x86_64-linux-gnu/ | grep libssl.so......)
ln -s /usr/lib/x86_64-linux-gnu/${libcrypto} ~/libssl1.0-dev/lib/x86_64-linux-gnu
ln -s /usr/lib/x86_64-linux-gnu/${libssl} ~/libssl1.0-dev/lib/x86_64-linux-gnu
# Set your CFLAGS LDFLAGS compile options
# And use pyenv install the python version <3.4.5 or <3.5.3
# Note: it is a one line command
# Please change the version of python that you want to compile
CFLAGS="-I${HOME}/libssl1.0-dev/include -I${HOME}/libssl1.0-dev/include/x86_64-linux-gnu" \
LDFLAGS="-L${HOME}/libssl1.0-dev/lib/x86_64-linux-gnu" \
pyenv install 3.4.2
# Remove tempor libssl1.0-dev direcotory
rm -rf ~/libssl1.0-dev