【问题标题】:Error when importing ssl in Python 3.7.4 on macOS 10.14.6在 macOS 10.14.6 上的 Python 3.7.4 中导入 ssl 时出错
【发布时间】:2020-04-13 10:56:20
【问题描述】:

为什么尝试在 python3 中导入 ssl 时出现错误?

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

我很难通过 pip 安装软件包,这似乎引发了 SSL 错误。

【问题讨论】:

    标签: python-3.x ssl


    【解决方案1】:

    我遇到了完全相同的问题,当我使用 brew 将我的 Python 版本升级到 3.7.6 后,这个问题就解决了。

    brew upgrade python3
    

    这引发了一个权限被拒绝的错误,但更新仍然完成,之后我能够导入 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'>
    >>> 
    

    【讨论】:

    • 这解决了我愚蠢的 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")' 问题
    【解决方案2】:

    使用自制软件在 osx 上为我解决的问题是切换到旧版本的 openssl:

    brew switch openssl 1.0.2s
    

    看到这个SO article

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-20
      • 2021-03-11
      • 2020-01-27
      • 2021-04-16
      • 2020-09-03
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      相关资源
      最近更新 更多