python ImportError:urllib3 v2.0只支持OpenSSL 1.1.1+,目前'ssl'模块是用LibreSSL 2.8.3编译的

csga3l58  于 2023-05-27  发布在  Python
关注(0)|答案(4)|浏览(4590)

pip install openai之后,当我尝试import openai时,它显示以下错误:

the 'ssl' module of urllib3 is compile with LibreSSL not OpenSSL

我刚刚学习了一个关于使用OpenAI API的项目教程。但是当我进入第一步安装和导入OpenAI时,我卡住了。我试图找到这个错误的解决方案,但我什么也没找到。
以下是我尝试导入OpenAI后的消息:

Python 3.9.6 (default, Mar 10 2023, 20:16:38) 
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openai
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yule/Library/Python/3.9/lib/python/site-packages/openai/__init__.py", line 19, in <module>
    from openai.api_resources import (
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/__init__.py", line 1, in <module>
    from openai.api_resources.audio import Audio  # noqa: F401
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/audio.py", line 4, in <module>
    from openai import api_requestor, util
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_requestor.py", line 22, in <module>
    import requests
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py", line 38, in <module>
    raise ImportError(
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/2168

我试着--upgradeurllib3,但仍然不工作,结果是:

pip3 install --upgrade urllib3
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in ./Library/Python/3.9/lib/python/site-packages (2.0.2)
abithluo

abithluo1#

错误消息中提到OpenSSL 1.1.1+和LibreSSL 2.8.3的原因是urllib3 v2.0(您安装的版本)需要OpenSSL 1.1.1+才能正常工作,因为它依赖于OpenSSL 1.1.1的一些新功能。问题是当前安装在您的环境中的'ssl'模块版本是用LibreSSL 2.8.3编译的,它与urllib3 v2.0不兼容。
要使用urllib3 v2.0,您需要使用OpenSSL 1.1.1或更高版本编译的'ssl'模块,方法是尝试:

brew install openssl@1.1

或者你可以使用一个旧版本的urllib3,它是兼容的。例如urllib3 v1.26.6,它没有严格的OpenSSL版本要求。您可以使用以下命令强制安装版本:

pip install urllib3==1.26.6
cidc1ykv

cidc1ykv2#

我也遇到了这个问题。我的旧版本是Python 3.9。“brew install openssl@1.1”不适合我。
您可以尝试:
pipenv install --python 3.11
这解决了我的问题。

5t7ly7z5

5t7ly7z53#

您应该升级系统的LibreSSL版本。使用brew upgrade openssl@1.1

lyr7nygr

lyr7nygr4#

在MacBook Air M1上工作时遇到了同样的问题。这对我很有用

pip uninstall urllib3
pip install 'urllib3<2.0'

相关问题