11

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

hafiz031
  • 2,236
  • 3
  • 26
  • 48

5 Answers5

20

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.

Kirk
  • 1,779
  • 14
  • 20
  • 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 altinstall` – hafiz031 Jul 25 '20 at 03:52
  • 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. – hafiz031 Jul 25 '20 at 03:56
  • 1
    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. – Kirk Jul 25 '20 at 04:00
  • 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 wget` – hafiz031 Jul 25 '20 at 04:06
  • 1
    Did you then re-configure, and then rebuild your python? I've updated the answer to call that out a bit. – Kirk Jul 25 '20 at 04:06
  • Rebuild?? Oh! Sorry, not actually. – hafiz031 Jul 25 '20 at 04:08
  • 1
    The output of your `./configure --enable-optimizations` should call out including/excluding ssl support FYI – Kirk Jul 25 '20 at 04:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218556/discussion-between-kirk-and-hafiz031). – Kirk Jul 25 '20 at 04:11
  • 3
    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. – hafiz031 Jul 25 '20 at 04:16
  • 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.9 – Vladimir Gorovoy Feb 08 '21 at 12:43
  • 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. – Casey Jones Oct 24 '21 at 20:01
  • 2
    Install dependencies listed in the Python dev guide https://devguide.python.org/setup/#linux – Jacek Trociński Mar 26 '22 at 15:43
3

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.

altschuler
  • 3,694
  • 2
  • 28
  • 55
  • Can you explain your answer ? What does it mean "being read but not found" ? How do you read something that you don't find ? – Eduardo Feb 28 '23 at 17:18
  • 1
    I meant to say that it was attempted to be read, but could not be found. – altschuler Feb 28 '23 at 20:07
  • On Ubuntu 22.04 this fixed it for me. I used the accepted answer in this question: https://stackoverflow.com/questions/72133316/libssl-so-1-1-cannot-open-shared-object-file-no-such-file-or-directory – TobyHijzen Jul 12 '23 at 11:19
3

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

choco install wget openssl
Ncrefe
  • 31
  • 1
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.

Mykola Tetiuk
  • 157
  • 3
  • 9
0

If you've installed pyenv, uninstall it.

rm -rf $(pyenv root)
Dhruv
  • 1
  • 1
  • 2
    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](/help/how-to-answer). – Community Aug 25 '23 at 21:36