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

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

当前回答

问题可能来自您安装的openssl包版本。这就是我的情况,我解决了这个问题,只是升级它。我在Mac OS上,使用brew:

brew upgrade openssl

如果你用brew安装了python,这应该会直接修复这个问题,因为python依赖于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。

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

安装python3-openssl

你可以尝试brew链接,它会告诉你正确的说明:

$ brew link openssl --force
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

苹果操作系统

我在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 !