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

7

14

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).

Pitchfork answered 25/7, 2020 at 3:35 Comment(1)
G
21

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.

Gales answered 25/7, 2020 at 3:46 Comment(13)
I installed python3.7.5 in the following way: sudo apt install build-essential mkdir ~/python-source-files wget -P ~/python-source-files https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz tar xvzf Python-3.7.5.tgz cd Python-3.7.5 ./configure --enable-optimizations sudo make altinstallPitchfork
After that I also used update-alternatives to set a priority to them. Although I could not have done it as I am directly mentioning the pip version while executing the pip commands and before doing this I got the same error.Pitchfork
this looks to have changed a bit since I last did it. It could be that you just didn't have the ssl development headers present, so ssl support wasn't built. Let's make sure all your build packages are present; sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget. After that, try re-configuring python and look carefully at the output of config. You should see something about ssl being enabled.Gales
No, still getting the same error after installing sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wgetPitchfork
Did you then re-configure, and then rebuild your python? I've updated the answer to call that out a bit.Gales
Rebuild?? Oh! Sorry, not actually.Pitchfork
The output of your ./configure --enable-optimizations should call out including/excluding ssl support FYIGales
Let us continue this discussion in chat.Gales
Yes after sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget I executed ./configure --enable-optimizations (going to Python3.7 directory) and executed sudo make altinstall and now it is working fine.Pitchfork
Thanks, this one helped in my case before installing python from sources: sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget With python 3.6 didn't have this problem at all, only happened when I tried to install 3.9Feigin
The correct answer seems to be installing the right dependencies, rather than enabling --with-openssl, which - as you point out - is enabled by default. This is a good answer, but it could be much more concise, and would be more clear if missing dependencies were mentioned first.Tropicalize
Install dependencies listed in the Python dev guide devguide.python.org/setup/#linuxBoccie
From May 6th installing Python 3.12.3: configure: error: Invalid --with-openssl valueWares
P
5

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.

Phenomenalism answered 23/12, 2022 at 21:33 Comment(3)
Can you explain your answer ? What does it mean "being read but not found" ? How do you read something that you don't find ?Hammock
I meant to say that it was attempted to be read, but could not be found.Phenomenalism
On Ubuntu 22.04 this fixed it for me. I used the accepted answer in this question: #72133816Burke
S
3

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

choco install wget openssl
Sizemore answered 24/2, 2023 at 20:47 Comment(0)
V
2

openssl is no more supported in centos7, To fix this issue, you must build python using openssl11 package instead of openssl, to do so:

  • first install openssl11

    sudo yum install -y epel

    sudo yum install -y openssl11-devel

  • build python:

    cd Python-3.1X.X

    sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure

    ./configure --enable-optimizations

    make altinstall

Vietcong answered 18/9, 2023 at 15:37 Comment(0)
L
0

Ubuntu 22.04

python -m pip install virtualenv

That has revealed that I needed to add ~/.local/bin to $PATH

export PATH=~/.local/bin:$PATH

After that pip install --user conan or pip install conan should be successful.

Leibniz answered 8/5, 2023 at 10:14 Comment(0)
K
-1

If you've installed pyenv, uninstall it.

rm -rf $(pyenv root)
Kolyma answered 23/8, 2023 at 20:53 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hoodlum
F
-1

for windows,

delete the venv folder and recreate again.

Falco answered 26/10, 2023 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.