我正在运行:
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环境。它同时安装了Python 2.7.15和3.7.2。
常规(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
编辑:我现在注意到,当在Python3上运行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
第2版:
我的问题似乎与此相同。然而,除了描述问题之外,线程没有提供任何解决方案。
我试着用这个指南编译一个新版本的openssl。但更新的openssl版本并没有解决我的问题。
第3版:
我找不到解决这个问题的办法。
亚马逊的Linux版本似乎不能很好地与Python 3配合使用。
他们确实有一个不同的操作系统,称为Amazon Linux 2,在那里安装Python 3就像运行yum install python3
一样简单
然而,AmazonLinux2也有自己的问题。它的Python 2安装缺少pip
。您可以通过运行手动安装它
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user
但这实际上覆盖了pip3,所以Python3仍然没有pip
。
因此,此上下文中的SSLError("由于SSL模块不可用,无法连接到HTTPS URL。")表明当您从源代码编译python3.7时,它没有链接到您的系统OpenSSL库。迂腐的解决方案是确保除了lib之外还有所需的头,比如:$ yum install openssl-devel.x86_64 openssl.x86_64
,然后从头开始重新编译,链接到OpenSSL lib。
然而,正如您正确指出的那样,在EC2中使用yum(来自亚马逊自己的repo,针对亚马逊Linux测试的软件包)安装python3是一种更简单、更健壮的方法,可以解决所有依赖关系。例如,类似的东西将在AmazonLinux(版本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)
还有一些版本化的Python命令可与-m开关(用于模块)结合使用,以运行相应版本的pip,例如:$ python3 -m pip install --user flask
您通过get-pip.py --user
安装的一个可能已位于$HOME/.local/bin目录中的某个位置。--user
交换机只为当前用户安装软件包(在~/.local/lib/中),而不是为整个系统安装软件包,这实际上是避免干扰系统python软件包的一种很好的做法。
更好的是,您可以在virtualenv或venv隔离的环境中使用pip:有python36 virtualenv(可通过yum安装),以及内置Python3且随时可用的默认"venv"模块(python3 -m venv yournewenvname
)。创建并激活隔离的python环境(一个目录)后,无论python版本如何,都可以在那里执行简单的pip install flask
。祝你好运
您可以忽略ssl错误或安装打开的ssl。你应该试试这个答案。