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

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

当前回答

苹果操作系统

我在Mac OS(Mojave)上遇到了同样的问题,并解决了这个链接中提到的问题- Openssl问题。

如果你没有Homebrew或不知道什么是Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

或者如果你已经安装了Homebrew:

brew update && brew upgrade
brew uninstall --ignore-dependencies openssl; brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

更新: 请记住,我必须使用——ignore-dependencies标记,因为安装的其他包依赖于OpenSSL。

另外,如果问题是在使用pyenv后引起的,您可以通过使用以下方法修复:

brew reinstall python

其他回答

先安装openssl。

如果你在conda环境中遇到这个问题,你可以安装openssl 使用conda install -c anaconda openssl。它为您启用ssl !

我用的是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之后,它修复了这个问题。

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

安装python3-openssl

与上述解决方案类似,使用pyenv重新安装python版本。

不知何故,我升级了我的openssl,它破坏了pyenv版本的python。

pyenv install 3.6.8
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
...

第一行说它依赖于自制的openssl。

为我工作。

sudo apt-get install libssl-dev

使用此选项为pip启用ssl。 如果有人遇到问题请告诉我。