SSLError(“无法连接到 HTTPS URL,因为 SSL 模块不可用。”)

问题描述 投票:0回答:5

在我的

Ubuntu 20.04
。我正在使用两个
python
版本。其中之一是
Python3.8.2
,它随我的
Ubuntu
安装一起提供,另一个是
Python3.7.5
。我使用
Python3.7.5
和系统默认版本一起安装了
update-alternatives
。但现在的问题是没有
pip
命令对
Python3.7.5
起作用。虽然
pip
在此 (
Python3.7.5
) 安装中可用,但在打印版本时,它显示以下内容(使用命令
pip3.7 -V
):

pip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

但是每当我尝试使用它安装软件包时总是显示标题中提到的错误。例如,在安装以下软件包时:

sudo pip3.7 install intel-tensorflow==1.15.2

抛出以下错误:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting intel-tensorflow==1.15.2
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/intel-tensorflow/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/intel-tensorflow/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/intel-tensorflow/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/intel-tensorflow/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/intel-tensorflow/
  Could not fetch URL https://pypi.org/simple/intel-tensorflow/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/intel-tensorflow/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  ERROR: Could not find a version that satisfies the requirement intel-tensorflow==1.15.2 (from versions: none)
ERROR: No matching distribution found for intel-tensorflow==1.15.2
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

为什么会发生这种情况? 无论我要安装哪个模块,所有 pip3.7 安装都会显示相同的错误。而且每当我使用系统默认的python版本时就不会出现这样的问题(

Python3.8.2
)。

python ssl pip python-3.7 tls1.2
5个回答
20
投票

TL;DR 您可能缺少一些系统依赖项。

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

请阅读下文,了解我们如何实现这一目标的完整详细信息。

错误表明SSL python模块不可用;这意味着您要么没有安装适当的 ssl 库(可能不是因为您声明系统 python 可以 pip install 正常),要么您从源代码构建或以其他方式安装的 python 不包含 ssl 模块。

如果您从源代码构建它,则需要确保设置配置选项

--with-openssl

另外,我真的要警告不要使用 sudo pip 安装任何东西。使用类似 virtualenv 的东西可以将 python 环境与系统 python 或您安装的其他 python 版本分开。

编辑:

经过仔细检查,假设存在 dev 标头,python 配置脚本似乎默认启用 ssl 支持。确保所有开发标头都存在

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
,然后重试配置和构建 python。


3
投票

在 Manjaro/Arch Linux 上我必须安装

openssl-1.1

在 python repl 中运行

import ssl
显示 libssl.so.1.1 正在被读取但未找到。


3
投票

对于 Windows,请在运行实际命令之前运行以下命令:

choco install wget openssl

0
投票

Ubuntu 22.04

python -m pip install virtualenv

这表明我需要将

~/.local/bin
添加到
$PATH

export PATH=~/.local/bin:$PATH

之后

pip install --user conan
pip install conan
应该会成功。


0
投票

如果您安装了 pyenv,请将其卸载。

rm -rf $(pyenv root)
© www.soinside.com 2019 - 2024. All rights reserved.