Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL module in Python is not available (on OSX)

Tags:

python

macos

ssl

I'm having trouble running pip install in a virtualenv on OSX 10.13. I already have run brew install openssl and the path /usr/local/include/openssl points to ../opt/openssl/include/openssl. Does anyone know how to fix this? This started happening after I reinstalled python using brew install.

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting Pillow Could not fetch URL https://pypi.python.org/simple/pillow/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping Could not find a version that satisfies the requirement Pillow (from versions: ) No matching distribution found for Pillow

UPDATE: Here's some more info:

✗ which python /usr/local/opt/python/libexec/bin/python 
✗ which pip /usr/local/opt/python/libexec/bin/pip 
✗ python --version Python 3.7.4 
✗ pip --version pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7) 
✗ brew info python python: stable 3.7.4 (bottled), HEAD Interpreted, interactive, object-oriented programming language https://www.python.org/ /usr/local/Cellar/python/3.6.5_1 (4,795 files, 100.0MB)   Poured from bottle on 2019-10-08 at 14:39:37 /usr/local/Cellar/python/3.7.4_1 (3,903 files, 60.6MB) *   Poured from bottle on 2019-10-08 at 14:37:10 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb 

Yes, I have both 3.6.5_1 and 3.7.4_1 installed as I may need to switch between the two at times.

✗ brew unlink openssl Unlinking /usr/local/Cellar/openssl/1.0.2s... 0 symlinks removed 
like image 507
John M. Avatar asked Oct 08 '19 05:10

John M.


People also ask

How do I fix SSL module is not available in Python?

The problem can be caused by DLLs in the Windows\System32 folder (e.g. libcrypto-1_1-x64. dll or libssl-1_1-x64. dll or others) placed there by other software. The fix was installing openSSL from https://slproweb.com/products/Win32OpenSSL.html which replaces the dlls by more recent versions.

Can't connect to https URL because the SSL module is not available python3?

To Solve Caused by SSLError(“Can't connect to HTTPS URL because the SSL module is not available.”) Error If you are using anaconda then Then add this to PATH variable <path>\Anaconda3 <path>\Anaconda3\scripts <path>\Anaconda3\Library\bin Second Solution is Just copy this file libcrypto-1_1-x64. * libssl-1_1-x64.

Can't connect to https URL because the SSL module is not available RHEL?

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.

What is SSL module?

This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side. This module uses the OpenSSL library.


2 Answers

The ssl module as well as its underlying C extension appears to be a part of the python formula:

Mac-Admin:~ admin$ python3 Python 3.7.4 (default, Sep  7 2019, 18:27:02)  [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>> ssl <module 'ssl' from '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py'> >>> import _ssl >>> _ssl <module '_ssl' from '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so'> 

so it being missing most probably means package installation corruption which brew reinstall python should fix.


Also note that while Homebrew allows multiple versions to coexist, its installation logic isn't quite designed to keep the alternative versions operational unless they are installed via a versioned formula (and e.g. routinely removes old versions in the regular brew cleanup).

So consider using pyenv (also available via brew) if you need to routinely switch between Python versions -- or some 3rd-party tap that offers versioned formulae for it.

like image 176
ivan_pozdeev Avatar answered Sep 28 '22 14:09

ivan_pozdeev


Mac OSX Catalina (and same issue on OSX Mojave) Pyenv

For anyone searching this topic, I had the same presenting problem, but had Python installed via both Homebrew and Pyenv!! It would have been better (IMO) to just use Pyenv to easily manage versions. As mentioned by @ivan_pozdeev in their answer, but here's some detail you might want.

If your situation is similar, none of the above solutions would be quite enough to set things right. Partially I was helped by a Pyenv related answer here: https://stackoverflow.com/a/51797298/3084820 I also happened to have pyenv-virtualenv installed, so mentioning that as well, as it's common to use these two together.

I finally took the following steps to resolve the issue:

brew uninstall python rm -rf $(pyenv root) brew uninstall pyenv-virtualenv   # you may not have this installed, but... brew uninstall pyenv 

Now, for a clean installation manageable with Pyenv:

brew install pyenv pyenv install 3.6.10  (or whatever version you want) 

This gave me a clean, working install of Python 3.6.10, and if I wanted or needed to, I could install a different version and switch between with Pyenv.

like image 39
Matt Morgan Avatar answered Sep 28 '22 15:09

Matt Morgan