pip已配置需要TLS/SSL的位置,但Python中的ssl模块不可用。

477

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

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

4
如果是OS X操作系统:https://dev59.com/aVsW5IYBdhLWcg3wM0yF - ZiTAL
3
操作系统是Oracle Linux 7.x。 - Santosh Kumar G
2
你是否从软件包管理器中安装了pip?如果你是通过编译安装的,那么请先安装libssl-dev或者通过pip安装ssl pip install ssl https://dev59.com/3FgR5IYBdhLWcg3woebW - ZiTAL
74
由于“ssl”的原因,“pip”无法正常工作,你需要使用pip安装“ssl” :) - ramazan polat
3
有没有不需要重新编译或重新安装 Python 的解决方案? - matanster
显示剩余5条评论
44个回答

1
我退出了我的虚拟环境并升级了pip。

1
我在使用 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 私有副本。由 Keychain Access 应用程序和 security 命令行实用程序管理的系统和用户密钥链中的信任证书不是 Python ssl 模块的默认值。

安装完3.8.5之后,问题得到了解决。

0

我遇到了这个问题!我不小心安装了32位的Miniconda3版本。请确保选择64位的版本!


0
这对我有用:
yum install python36-pyOpenSSL 

Python的版本和包管理器可能会有所不同。


0
我遇到了同样的问题,原因是我改变了环境的文件夹。 我只是删除了环境并重新安装了所有东西。

0
即使尝试了以上所有步骤,我仍然遇到了相同的错误。因此,在我们在实验室工作并具有授权访问Internet的情况下,问题出在服务器上的旧版本上。因此,我创建了一个虚拟环境,并将所有导入的模块放置在那里。为文件和用户提供了所有必要的权限。然后我给了服务器系统互联网访问权限。它正常工作了。 请检查您可能遇到的任何访问和权限问题。 希望能有所帮助。谢谢。

0

您可以尝试使用Anaconda提示符。

您会看到(base), 现在升级pip。 例如:

(base) C:\Users\Tom>cd ..

(base) C:\Users>cd ..

(base) C:\>python -m pip install --upgrade pip
Requirement already up-to-date: pip in g:\anaconda3\lib\site-packages (20.0.2)

(base) C:\>pip -V
pip 20.0.2 from G:\Anaconda3\lib\site-packages\pip (python 3.7)

# Try install
(base) C:\>pip install selenium

这需要更长的时间,但也会安装或升级 Anaconda 内部使用的 SSL 库。继续前进


此回答假定使用conda在Windows上,而不是OP所指示的Linux上的vanilla python。 - hrbdg

0
我遇到了同样的错误:
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模块不可用


0
你可以尝试使用brew link命令,它会显示正确的指令:
$ 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"

-1

在尝试自己编译Python并仍然缺少ssl模块后,我最终尝试了从apt安装缺失的模块,方法如下:

apt install python3-openssl


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接