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

haf*_*031 3 python ssl pip tls1.2 python-3.7

在我的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)
Run Code Online (Sandbox Code Playgroud)

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

sudo pip3.7 install intel-tensorflow==1.15.2
Run Code Online (Sandbox Code Playgroud)

抛出以下错误:

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
Run Code Online (Sandbox Code Playgroud)

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

Kir*_*irk 10

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

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

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

编辑:

仔细检查后,python configure 脚本似乎默认启用 ssl 支持,假设 dev 头文件存在。确保所有开发标头都存在sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget,然后重试配置和构建 python。

  • 是的,在 `sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget` 之后,我执行了 `./configure --enable-optimizations` (转到 Python3.7目录)并执行了`sudo make altinstall`,现在它工作正常。 (2认同)
  • 安装 Python 开发指南 https://devguide.python.org/setup/#linux 中列出的依赖项 (2认同)