Getting ignoring ensurepip failure pip requires ssl/tls error when trying to install python and pip in Ubuntu 18.04
Trying to run sudo make install
gets the above error.
# Download Python
curl -O https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
tar -xzvvf Python-3.4.2.tgz
cd Python-3.4.2
export CFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -I/usr/local/opt/zlib/include -L/usr/local/opt/zlib/lib"
# Required Dependencies
sudo apt-get install libssl-dev openssl
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libpq-dev zlib1g-dev
# Prepare to install Python
./configure
make -j4
sudo make install
This is a python compilation issue that has been fixed as of Python 3.4.5. Best practice would be to upgrade to 3.4.5 and follow the compilation steps again.
For those coming here for Python <3.5.3 with the same issue, this same issue has been fixed as of 3.5.3 (see here).
I am not sure if other Python versions are affected, but have seen in the Patch notes that in later versions also a fix was made for Windows and MacOSX. Please check the change log for the Python major version you are using to see which fix applies to you. the change logs can be found here: (Python 3.4, Python 3.5)
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With