Python 3.7无法连接到HTTPS URL,因为SSL模块不可用

问题描述 投票:7回答:4

我正在运行centos 6.10的专用服务器上安装Python 3.7。在跳过一些箍尝试这样做之后,我又遇到了另一个错误。使用Python 3.7尝试并保持最新,使用pip安装遇到SSL问题是一个相当常见的问题。我得出结论,解决这个问题的最好方法是获得正确版本的OpenSSL。所以我这样做了,编辑了我的python模块/ Setup.dist文件,重新配置它,重新制作altinstall,虽然一切看起来都很好。出于某种原因,命令Python3.7这是我以前用来运行这个python的命令,突然变得无法识别为命令,而在Python3.7目录中是一个文件夹python现在执行时(在编辑环境路径后打开了Python3.7。事先并非如此,它只是Python3.7有谁知道这里发生了什么?

此外,我对这整个SSL问题的最终结论,我已经阅读了太阳下的每一篇文章。以下列出了我最近执行的一些命令:

#Unpacked Python3.7 into /usr/src directory
./configure --enable-optimizations --enable-loadable-sqlite-extensions
make altinstall

#installation failed from no '_ctypes' module

yum install libffi-devel

#repeat configure above
#yaaay python
#Successfully installed pip-10.0.1 setuptools-39.0.1 was the final message of the installation

Python3.7 -m venv /my/project/directory/ENV
pip install {library}

#this is where my issues began with SSL

日志:

(ENV) [[email protected] ProjectDirectory]# pip3 install twisted
pip is configured with locations that require TLS/SSL, however, the SSL module in Python is not available.
Collecting twisted
  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/twisted/
  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/twisted/
  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/twisted/
  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/twisted/
  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/twisted/
  Could not fetch URL https://pypi.org/simple/twisted/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/twisted/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  Could not find a version that satisfies the requirement twisted (from versions: )
No matching distribution found for twisted
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 SSLmodule is not available.")) - skipping

所以我很酷。别担心。最新版本的Python甚至无法获得开箱即用的pip3。精彩。好吧,我开始搜索谷歌,并得出结论,每个人都只是重新配置他们的蟒蛇,它神奇地工作。不知道为什么,但好的。我进入了它。我找到了这篇文章:

https://techglimpse.com/install-python-openssl-support-tutorial/

好好冷静思考。如果我可以获得python3.7 SSL,那么应该让pip3工作正常吗?错误。不幸的是,如果我用上面提到的新奇怪的方式踢Python3.7,并输入import ssl我得到这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/src/Python-3.7.0/Lib/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

有人可以给我一些帮助吗?我有点迷失在海洋中,我不知道如何游泳...任何事情都会很棒,但我是这个服务器管理员的菜鸟所以越简单就越好:)谢谢你预先。

编辑:顺便说一下

yum install openssl

yum install openssl-devel

两者都导致'已经安装'标志......所以我认为这不是另一种解决方案。但是,当我手动安装时,我使用的是1.1.1版本,因为我知道3.7无论出于何种原因,都不再支持几个不同版本的OpenSSL。已经安装了yum的那个是1.0.2我想。虽然版本限制,我不知道centos 6.10平台是否有容量。

python ssl pip
4个回答
0
投票

我不确定你是否已经解决了这个问题,但是你必须确保在构建python时可以找到openssl库。

具体来说:如果你没有使用系统的ssl库,或者它们不在你的路径中,那么在--configure你需要指定它们的位置。我会给你一个确切的线,但我自己最近没有这样做。如果你已经正确地完成了这个,你就不会在构建结束时看到python跳过构建'ssl'模块的报告。当你看到上面有关于(_ssl)的错误时,这意味着python不是用它构建的。如果你在不改变--configure的情况下使用相同的步骤,你将在3.6中遇到同样的问题。


0
投票

我在尝试为Ubuntu 18.04 LTS编译Python 3.7.2时遇到了这个问题

确保您具有构建Python内置模块所需的所有依赖项。在make 2>&1 | tee make.txt之后运行configure并查找无法构建的模块的警告。如果模块无法构建,Python将不会使安装失败,它只是不会构建那些导致您看到的错误的模块。

安装依赖项后,请确保再次运行configure


0
投票

我在我的mac OS上遇到了类似的问题,由于SSL问题我无法在虚拟环境中安装任何东西甚至升级pip

What worked for me was doing the following from inside the virtual environment

  1. sudo chown -R ${whoami} /usr/local/Cellar紧随其后
  2. brew install openssl

What is the ${whoami} in the first command?

这是一个占位符;当你运行命令时你应该放在那里的是你当前的实际用户。

如果您不了解您的用户,请在命令行中键入

whoami

输出是您的用户。因此,如果您输入并将johnsmith作为输出,当您运行第一个命令时,您将用“${whoami}”替换“johnsmith”,如下所示:

sudo chown -R johnsmith /usr/local/Cellar


0
投票

配置选项“--with-openssl”适合我

© www.soinside.com 2019 - 2024. All rights reserved.