我使用的是Python 3.6。当我尝试使用pip3安装“模块”时,我遇到了这个问题:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

当前回答

我用的是macOS,我用过brew,但Vaulstein在他的回答中提到的并没有涵盖我的情况。

我运行以下命令,以确保我当前的python没有通过brew安装

brew list | grep python           
python
python@2

brew info python
python@3.8: stable 3.8.3 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
... 

所以我从https://www.python.org/下载了最新的3.8.5,安装时我看到了以下信息

证书验证和OpenSSL 此包包含自己的私有OpenSSL 1.1.1副本。的 管理的系统和用户密钥链中的信任证书 Python ssl模块不默认使用Keychain Access应用程序和安全命令行实用程序

在安装3.8.5之后,它修复了这个问题。

其他回答

我得到了同样的错误:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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/pb-tool/
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/pb-tool/
ERROR: Operation cancelled by user
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

在《Anaconda》中,我使用了以下命令:

conda install anaconda-navigator

本文中提到:pip配置了需要TLS/SSL的位置,但是Python中的SSL模块不可用

对于Windows 10下的Miniconda3, python=3.7.5,我尝试了以上所有建议;毫无效果。我不得不降级到python=3.7.0,这解决了这个问题

conda install python=3.7.0

显然这很混乱。答案表明升级到3.8.5也可以工作,但这在我的环境中有太多的副作用。

在尝试自己编译python后,仍然缺乏ssl模块,我最终尝试从apt安装缺少的模块,就像这样:

安装python3-openssl

对于未来试图解决这个问题的Oracle Linux用户,下面是对我有用的方法。 首先安装缺少的库:

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel 
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

然后cd到Python3。X库并运行:

make
make install 

Windows 10, Windows 7 如果pip install在CMD提示符下不工作,使用Anaconda提示符运行它-它工作。

https://github.com/pypa/virtualenv/issues/1139