尝试使用Python 3.7.2 pip安装软件包会导致TLS / SSL错误

问题描述 投票:5回答:2

我正在跑步:

Amazon Linux AMI 2018.03.0

Linux ip-xxx-yy-z-ww 4.14.77-70.59.amzn1.x86_64 #1 SMP Mon Nov 12 22:02:45 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

多蟒蛇环境。它安装了Python 2.7.15和3.7.2。

Regular(Python2)pip工作顺利。

当我尝试运行pip3 install flask时,我收到以下错误:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting flask
  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/flask/
  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/flask/
  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/flask/
  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/flask/
  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/flask/
  Could not fetch URL https://pypi.org/simple/flask/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/flask/ (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 flask (from versions: )
No matching distribution found for flask
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

如果我尝试安装任何其他包,则会出现相同的错误。

pip3版本是18.1

添加--trusted-host pypi.org没有帮助。

安装ca证书没有帮助

根据以下指南安装Python 3:https://stackoverflow.com/a/8112006/8826349

编辑:我现在注意到,当在Python 3上运行make时,它成功完成,但有以下消息:

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_hashlib              _ssl                  _tkinter
_uuid
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd
time


Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

Aaditi:

我的问题似乎与this相同。但是,除了描述问题之外,该线程不提供任何解决方案。

我试图使用this指南编译更新版本的openssl。但是较新的openssl版本没有解决我的问题。

Aadita:

我无法找到解决此问题的方法。

亚马逊的Linux版本似乎与Python 3不兼容。

他们有一个不同的操作系统,称为Amazon Linux 2,安装Python 3就像运行yum install python3一样简单

但是,Amazon Linux 2有它自己的问题。它的Python 2安装缺少pip。您可以通过运行手动安装它:

curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user

但这实际上覆盖了pip3,因此Python 3仍然没有pip

python python-3.x pip python-3.7
2个回答
2
投票

因此,SSLError(“无法连接到HTTPS URL,因为SSL模块不可用。”)在此上下文中指示当您从源编译python3.7时,它没有链接到您的系统OpenSSL库。迂腐的解决方案是确保你拥有lib之外的所需标题,例如: $ yum install openssl-devel.x86_64 openssl.x86_64 并从头开始重新编译,链接到OpenSSL lib。

但是,正如您已正确指出的那样,使用yum安装python3(来自Amazon自己的repo,针对Amazon Linux测试的包)在EC2中更容易,更强大,并且将解决所有依赖关系。例如,类似这样的东西将在Amazon Linux(版本1)中起作用:

$ yum install python36.x86_64
$ yum install python36-pip.noarch

通常,Python3.6已预先安装在EC2中,但不是python36-pip ...

这是正确的默认行为,Python3的pip脚本由pip3命令调用,而pip用于Python2(如果已安装 - python2的yum包是python27-pip.noarch),例如:

$ pip3 -V  
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)  
$ pip2 -V  
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)  
$ pip -V  
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)  

还有与-m开关(用于模块)结合使用的版本化Python命令,以运行相应版本的pip,例如: $ python3 -m pip install --user flask

你通过get-pip.py --user安装的那个可能已经降落在$ HOME / .local / bin目录中。 --user开关只为当前用户(在〜/ .local / lib /中)而不是为整个系统安装软件包,这实际上是避免干扰系统python软件包的好习惯。

更好的是,你可以在virtualenv或venv隔离环境中使用pip:有python36-virtualenv(可通过yum安装),以及默认的'venv'模块内置Python3并且随时可用(python3 -m venv yournewenvname)。一旦你创建然后激活你的孤立的python环境(一个目录),你可以在那里做一个简单的pip install flask,无论python版本。祝好运!


0
投票

您可以忽略ssl错误或安装open-ssl。你应该尝试this答案。

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