0

Let me preface by saying, this question has come up a lot on Stack Overflow. I've read a number of those answers and tried many of the solutions, none of which have solved my issue. But first, here is the problem:

Some things I've tried (not exhaustive):

pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
python3 -m pip install <package_name>
pip3 install <package name>

More or less the same error every time:

Defaulting to user installation because normal site-packages is not writeable
Could not fetch URL https://pypi.org/simple/venv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/venv/ (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 venv (from versions: none)
ERROR: No matching distribution found for venv
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

I'm running this on WSL2 Ubuntu 20.04. I appreciate any thoughts or suggestions. I've also completely reinstalled python, tried different versions of python, reinstalled pip, tried different versions of pip, and a number of other things.

Edit: Result of type -a python3 python3.8 , python3 , import ssl

python3 is /usr/local/bin/python3
python3 is /usr/bin/python3
python3 is /bin/python3
python3.8 is /usr/local/bin/python3.8
python3.8 is /usr/bin/python3.8
python3.8 is /bin/python3.8
#@#:/usr/local/lib$ python3
Python 3.8.6 (default, Nov 19 2020, 14:27:22)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
Artemis
  • 35
  • 6
  • `python3 -m ensurepip` – Pedro Lobito Feb 23 '21 at 22:23
  • How did you install/reinstall Python? It looks like this can happen if you built it from source. See [this answer](https://stackoverflow.com/a/49696062/4518341) – wjandrea Feb 23 '21 at 22:24
  • @PedroLobito ensurepip works and says all conditions are satisfied. – Artemis Feb 23 '21 at 22:34
  • @wjandrea I am trying to do that answer now, but cannot find the ./configure file in /usr/local/lib/Python3.8. Is that where I should be expecting it? – Artemis Feb 23 '21 at 22:35
  • @Artemis Well, how did you install/reinstall Python? – wjandrea Feb 23 '21 at 22:37
  • @wjandrea Just via ```sudo apt-get install python3.8``` – Artemis Feb 23 '21 at 22:39
  • @Artemis Hmm, that should include the `ssl` module. I installed it the same way on my 18.04, non-WSL. Did you try `python3.8 -m pip ...`? – wjandrea Feb 23 '21 at 22:42
  • @wjandrea I did, yes. I can try to reinstall python again if you think that is a good idea. – Artemis Feb 23 '21 at 22:45
  • Oh actually, 3.8 is the default version on 20.04, so you should never need to modify it. Maybe there's something weird going on with WSL, but try this first: `type -a python3 python3.8` and make sure that they're `/usr/bin/python3` and `/usr/bin/python3.8` respectively. Then run `python3` and try `import ssl`. – wjandrea Feb 23 '21 at 22:47
  • 1
    @wjandrea I added the result of that to my original answer, as it was a bit much for a comment. – Artemis Feb 23 '21 at 22:53

2 Answers2

1

The problem is that you have "local" installs of python3 and python3.8 in /usr/local/bin which apparently don't have the ssl module. They're higher in the PATH, so they're overriding the system installs in /usr/bin

So for the meantime, you should be able to use pip like this:

/usr/bin/python3 -m pip ...

Ultimately, you'll probably want to remove the local installs. However, you haven't mentioned how you installed them, so I don't have any more details than that. Possibly, you built from source then did make altinstall.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
-2

I got this error for other pip installs.

Try using -m pip3 install <package_name>

instead of -m pip install <package_name>

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • I tried this, but get ```no module named pip3``` even though I have pip3 installed. So I'm guessing maybe pip3 is in the wrong place? Currently it's in usr/local/bin – Artemis Feb 23 '21 at 22:26
  • @Artemis Yeah, `pip3` isn't the name of the module. IDK what they're talking about. – wjandrea Feb 23 '21 at 22:38
  • Are you using some VPN or private network to do this? – Sunny Feb 23 '21 at 23:02