題意:
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3
當前使用的?urllib3
?版本(v2.0)僅支持 OpenSSL 1.1.1 或更高版本,但你的 Python 環境中的?ssl
?模塊卻是用 LibreSSL 2.8.3 編譯的
問題背景:
After?pip install openai
, when I try to?import openai
, it shows this error:
安裝了openai
庫之后嘗試導入 openai 時出現的錯誤:
the 'ssl' module of urllib3 is compile with LibreSSL not OpenSSL
I just followed a tutorial on a project about using API of OpenAI. But when I get to the first step which is the install and import OpenAI, I got stuck. And I tried to find the solution for this error but I found nothing.
我剛剛按照一個關于使用OpenAI API的項目的教程進行操作。但當我進行到第一步,即安裝和導入OpenAI時,我遇到了問題。我嘗試尋找這個錯誤的解決方案,但什么也沒找到。
Here is the message after I try to import 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 openaiTraceback (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: F401File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/audio.py", line 4, in <module>from openai import api_requestor, utilFile "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_requestor.py", line 22, in <module>import requestsFile "/Users/mic/Library/Python/3.9/lib/python/site-packages/requests/__init__.py", line 43, in <module>import urllib3File "/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
I tried to?--upgrade
?the?urllib3
, but it is still not working. The result is:
我嘗試對urllib3
進行升級,但是仍然不起作用。結果是:
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)
問題解決:
The reason why the error message mentioned OpenSSL 1.1.1+ and LibreSSL 2.8.3 is that urllib3 v2.0 (the version you've installed) requires OpenSSL 1.1.1+ to work properly, as it relies on some new features of OpenSSL 1.1.1.
錯誤消息中提到OpenSSL 1.1.1+和LibreSSL 2.8.3的原因是,您已安裝的urllib3
?v2.0版本需要OpenSSL 1.1.1+才能正常工作,因為它依賴于OpenSSL 1.1.1的一些新功能。LibreSSL雖然與OpenSSL相似,但在某些方面可能不完全兼容,特別是如果它的版本低于OpenSSL 1.1.1,則可能不包含urllib3
?v2.0所需的功能。
The issue is that the version of the 'ssl' module that is currently installed in your environment is compiled with LibreSSL 2.8.3, which is not compatible with urllib3 v2.0.
問題是,當前在您的環境中安裝的'ssl'
模塊版本是使用LibreSSL 2.8.3編譯的,這與urllib3
?v2.0不兼容。
To use urllib3 v2.0, you need an 'ssl' module compiled with OpenSSL 1.1.1 or later, by trying:
為了使用urllib3
?v2.0,您需要一個使用OpenSSL 1.1.1或更高版本編譯的'ssl'
模塊。您可以嘗試以下方法來解決這個問題:
brew install openssl@1.1
Or you could use an older version of urllib3 that is compatible suc. For example urllib3 v1.26.6, which does not have a strict OpenSSL version requirement. You can force the version installing with this command:
或者,可以使用與LibreSSL兼容的舊版本的urllib3
。例如,urllib3
?v1.26.6就沒有嚴格的OpenSSL版本要求。您可以使用以下命令強制安裝特定版本
pip install urllib3==1.26.6