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

Pix*_*398 9 python ssl

我正在运行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
Run Code Online (Sandbox Code Playgroud)

日志:

(ENV) [root@s1.1.1.1 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
Run Code Online (Sandbox Code Playgroud)

所以我很酷.别担心.最新版本的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'
Run Code Online (Sandbox Code Playgroud)

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

编辑:顺便说一下

yum install openssl
Run Code Online (Sandbox Code Playgroud)

yum install openssl-devel
Run Code Online (Sandbox Code Playgroud)

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

hlp*_*hlp 5

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

对我有用的是在虚拟环境中执行以下操作

  1. sudo chown -R ${whoami} /usr/local/Cellar其次是

  2. brew install openssl

${whoami}第一个命令中的是什么?

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

如果您不知道您的用户,请在命令行中输入

whoami

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

sudo chown -R johnsmith /usr/local/Cellar


Ebr*_*med 2

我不确定你是否已经弄清楚了这一点,但你必须确保在构建 python 时它可以找到 openssl 库。

具体来说:如果您没有使用系统 ssl 库或者它们不在您的路径中,则需要在 --configure 中指定它们的位置。我会给你确切的路线,但我自己最近还没有这样做过。如果您正确完成了此操作,您将不会在构建结束时看到有关 python 跳过构建“ssl”模块的报告。当您看到上面关于 (_ssl) 的错误时,这特别意味着 python 不是用它构建的。如果您使用相同的步骤而不更改 --configure,您将在 3.6 中面临相同的问题。