pip 命令中的 SSLError(“无法连接到 HTTPS URL,因为 SSL 模块不可用.") [英] SSLError("Can't connect to HTTPS URL because the SSL module is not available.") in pip command

查看:127
本文介绍了pip 命令中的 SSLError(“无法连接到 HTTPS URL,因为 SSL 模块不可用.")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Ubuntu 20.04 中.我正在使用两个 python 版本.其中一个是 Python3.8.2,它是我的 Ubuntu 安装附带的,另一个是 Python3.7.5.我使用 update-alternatives 和系统默认版本一起安装了 Python3.7.5.但现在的问题是没有 pip 命令在 Python3.7.5 上运行.尽管 pip 在此 (Python3.7.5) 安装中可用,并且在打印版本时显示以下内容(使用命令 pip3.7 -V):

In my Ubuntu 20.04. I am using two python versions. One of them is Python3.8.2 which came with my Ubuntu installation and another one is Python3.7.5. I installed Python3.7.5 using update-alternatives alongside the system default version. But now the problem is no pip command is working on Python3.7.5. Although pip is available in this (Python3.7.5) installation and while printing the version it shows the following (using command pip3.7 -V):

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

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

But whenever I try to install a package using it always shows the error mentioned in the title. For example while installing the following package:

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) 时,也不会有这样的问题.

Why this is actually happening? Again it shows the same error for all pip3.7 installations no matter which module I am going to install. Also there is no such problems like that whenever I am using the system default python version (Python3.8.2).

推荐答案

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

The error states that the SSL python module is not available; meaning you either don't have an appropriate ssl lib installed (probably not since you state the system python can pip install fine), or the python you built from source or otherwise installed doesn't include the ssl module.

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

If you built it from source, you need to be sure to set the configuration option --with-openssl.

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

Also, I'd really caution against sudo pip installing anything. Use something like virtualenv to have separate python environments from the system python or other python versions you install.

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

Upon closer examination, the python configure script appears to enable ssl support by default, assuming the dev headers are present. Make sure all the dev headers are present with sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget, then retry configuring and building python.

这篇关于pip 命令中的 SSLError(“无法连接到 HTTPS URL,因为 SSL 模块不可用.")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆