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 due to
Debian 9
usingOpenSSL 1.1.0
., However,OpenSSL 1.1.0
support in the SSL module was only added to Python2.7.13
,3.5.3
and3.6+
Thus, it makes the python under those versions cannot be correctly linked tossl
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 usesshims
, through a process called rehashing,pyenv
maintainsshims
in that directory to match every Python command across every installed version ofpython
,pip
, and so on. For more documents, please reading: https://github.com/pyenv/pyenv. To installpyenv
, 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.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)