Ubuntu – Pip3 reinstall on Ubuntu 18.04

18.04pippython3

Recently I have faced with the issue that on Ubuntu 18.04 pip3 does not work properly:

:~$ pip3 install jinja2
Traceback (most recent call last):
  File "/home/redra/.local/bin/pip3", line 7, in <module>
    from pip import main
ModuleNotFoundError: No module named 'pip'

Then I have tried to reinstall pip3, seems like it is due to it and faced with another issue:

:~$ sudo -H python3 get-pip.py
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pip
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/

I guess it is stucking … I cannot install openssl due to bad pip3 and cannot install a new pip3 due to openssl … Seems like it is cycle (

Any suggestion ? Has anybody faced with the same issue ?

Best Answer

This is probably because the required openssl binaries were not present when you compiled python, to fix this

  • download openssl (tar.gz shall do the trick) from: https://www.openssl.org/source/

  • untar SSL source in folder

  • Goto the folder and run the following to make openssl

    ./configure && make && sudo make install

Finally - redo the Python compilation (configure, make, make install), observe that ssl library now compiles into Python as it appears in standard place where Python compiling procedure is looking for.

Related Question