python中报"urllib3 v2.0 only supports OpenSSL 1.1.1+, currently " ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.1.0i 14 Aug 2018. See
时间: 2023-06-28 18:04:45 浏览: 2512
这个错误是由于你的 Python 环境中的 `ssl` 模块使用的 OpenSSL 版本不符合 `urllib3` 的要求。为了解决这个问题,你需要更新你的 OpenSSL 版本。
如果你使用的是 Linux 或 macOS 系统,你可以通过包管理器来升级 OpenSSL。例如,如果你使用的是 Ubuntu 系统,可以通过以下命令升级 OpenSSL:
```
sudo apt-get update
sudo apt-get install openssl
```
如果你使用的是 macOS 系统,可以通过 Homebrew 包管理器来升级 OpenSSL:
```
brew update
brew install openssl
```
如果你使用的是 Windows 系统,你可以从 OpenSSL 官网下载最新版本的 OpenSSL,并按照官方文档进行安装。
安装完 OpenSSL 后,你需要重新编译 Python 的 `ssl` 模块,使其链接到新的 OpenSSL 库。具体步骤如下:
1. 打开命令行界面,进入 Python 的安装目录中的 `Modules/_ssl` 目录。
2. 运行以下命令,生成 `_ssl.c` 文件:
```
python _ssl.c.py openssl_dir=<path-to-openssl> [debug]
```
其中 `<path-to-openssl>` 是你安装 OpenSSL 的路径,`[debug]` 是可选参数,表示生成调试版本的 `_ssl.c` 文件。
例如,如果你在 macOS 系统上使用 Homebrew 安装了 OpenSSL,那么 `<path-to-openssl>` 可能是 `/usr/local/opt/openssl`。
3. 运行以下命令,编译 `_ssl` 模块:
```
python setup.py build_ssl
```
4. 运行以下命令,安装 Python:
```
python setup.py install
```
这样,你就可以在 Python 中使用最新版本的 OpenSSL 和 `urllib3` 了。
阅读全文
相关推荐













