9

Why am I getting an error when trying to import ssl in python3 ?

Python 3.7.4 (default, Jul  9 2019, 18:13:23) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
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/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: dlopen(/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/_ssl.cpython-37m-darwin.so
  Reason: image not found

I am having a hard time installing packages via pip which seem to be throwing an SSL error.

anjanesh
  • 3,771
  • 7
  • 44
  • 58

2 Answers2

13

I had exactly the same problem, which was solved once I upgraded my Python version to 3.7.6 using brew.

brew upgrade python3

This threw a permission denied error, but the update was done nonetheless, after which I was able to import ssl:

Python 3.7.6 (default, Dec 30 2019, 19:38:28) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl
<module 'ssl' from '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py'>
>>> 
Bart Barnard
  • 1,128
  • 8
  • 17
  • 1
    this solved my dumb 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")' issue – blah blah May 06 '20 at 13:54
8

What fixed it for me on osx using homebrew was switching to an older version of openssl:

brew switch openssl 1.0.2s

See this SO article

David Schumann
  • 13,380
  • 9
  • 75
  • 96