SSLError("Can't connect to HTTPS URL because the SSL module is not available.") in pip command

Question:

In my Ubuntu 20.04. I am using two python versions. One of them is Python3.8.2 which came with my Ubuntu installation and another one is Python3.7.5. I installed Python3.7.5 using update-alternatives alongside the system default version. But now the problem is no pip command is working on Python3.7.5. Although pip is available in this (Python3.7.5) installation and while printing the version it shows the following (using command pip3.7 -V):

pip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

But whenever I try to install a package using it always shows the error mentioned in the title. For example while installing the following package:

sudo pip3.7 install intel-tensorflow==1.15.2

The following error is thrown:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting intel-tensorflow==1.15.2
  WARNING: 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/intel-tensorflow/
  WARNING: 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/intel-tensorflow/
  WARNING: 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/intel-tensorflow/
  WARNING: 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/intel-tensorflow/
  WARNING: 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/intel-tensorflow/
  Could not fetch URL https://pypi.org/simple/intel-tensorflow/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/intel-tensorflow/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  ERROR: Could not find a version that satisfies the requirement intel-tensorflow==1.15.2 (from versions: none)
ERROR: No matching distribution found for intel-tensorflow==1.15.2
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

Why this is actually happening? Again it shows the same error for all pip3.7 installations no matter which module I am going to install. Also there is no such problems like that whenever I am using the system default python version (Python3.8.2).

Asked By: hafiz031

||

Answers:

TL;DR you’re probably missing some system dependencies. sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Read below for the full details on how we got there.

The error states that the SSL python module is not available; meaning you either don’t have an appropriate ssl lib installed (probably not since you state the system python can pip install fine), or the python you built from source or otherwise installed doesn’t include the ssl module.

If you built it from source, you need to be sure to set the configuration option --with-openssl.

Also, I’d really caution against sudo pip installing anything. Use something like virtualenv to have separate python environments from the system python or other python versions you install.

EDIT:

Upon closer examination, the python configure script appears to enable ssl support by default, assuming the dev headers are present. Make sure all the dev headers are present with sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget, then retry configuring and building python.

Answered By: Kirk

On Manjaro/Arch Linux I had to install openssl-1.1.

Running import ssl in a python repl revealed that libssl.so.1.1 was being read but not found.

Answered By: altschuler

For windows run following command before you run your actual command:

choco install wget openssl
Answered By: Ncrefe
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.