我已经在我的本地机器上成功安装了Python 3.4和Python 3.6,但无法安装带有pip3的包。

当我执行pip3 install <package>时,我得到以下SSL相关错误:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting <package>
  Could not fetch URL https://pypi.python.org/simple/<package>/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement <package> (from versions: )
No matching distribution found for <package>

如何修复我的Python3。pip install <package>?


当前回答

ssl模块是用于访问操作系统(OS)套接字(Lib/ssl.py)的TLS/ ssl包装器。因此,当ssl模块不可用时,可能是您没有安装OS OpenSSL库,或者在安装Python时没有找到这些库。让我们假设这是后面的情况(也就是说:你已经安装了OpenSSL,但在安装Python时没有正确链接它们)。

我还假定您是从源代码安装的。如果你是从二进制文件(例如:windows .exe文件),或包(Mac .dmg,或Ubuntu apt)安装,在安装过程中你可以做的不多。

在配置python安装的步骤中,您需要指定将使用OS OpenSSL进行链接的位置:

# python 3.8 beta
./configure --with-openssl="your_OpenSSL root"

那么,在哪里可以找到已安装的OpenSSL目录呢?

# ubuntu 
locate ssl.h | grep '/openssl/ssl.h'

/home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
/home/user/envs/py37/include/openssl/ssl.h
/home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
/home/user/miniconda3/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
/usr/include/openssl/ssl.h

您的系统可能与我的不同,但正如您在这里看到的,我安装了许多不同的openssl库。在撰写本文时,python 3.8期望openssl 1.0.2或1.1:

Python要求使用X509_VERIFY_PARAM_set1_host()与OpenSSL 1.0.2或1.1兼容的libssl。

因此,您需要验证哪些已安装的库可以用于链接

/usr/bin/openssl version

OpenSSL 1.0.2g  1 Mar 2016
./configure --with-openssl="/usr"
make && make install

您可能需要尝试一些库,或者安装一个新的库,以找到适合您的Python和操作系统的库。

其他回答

好的,这个问题的最新答案是,到目前为止不要使用Python 3.8,只使用3.7或更少的版本,因为大多数库都无法安装上面的错误

前两天我也遇到了同样的问题,直到现在才解决。

我尝试使用digicert_high_asance_ev_root_ca的——trust-host选项。pem不工作,我无法安装ssl模块(它告诉它不能安装python版本大于2.6),设置$PIP_CERT变量也没有修复它,我安装了libssl1.0.2和libssl1.0.0。值得一提的是,我没有~/.pip/pip.conf文件,创建它也没有解决这个错误。

最终解决这个问题的方法是再次使用make安装python3.6。 下载Python-3.6.0。从网站TGZ,运行配置,然后使,使测试,使安装。希望这对你有用。

如果你在Windows上使用Anaconda,你可以尝试在Anaconda提示符中运行“pip install…”命令,而不是cmd.exe,就像用户willliu1995在这里建议的那样。这对我来说是最快的解决方案,不需要安装额外的组件。

(Windows上不行!)

这让我抓狂了一个星期,所以我希望这能帮助到一些人

除了重新安装Anaconda和/或Jupyter,我尝试了所有方法。

设置

AWS Linux 手动安装Anaconda 3-5.3.0 Python3(3.7)在anaconda(即。/anaconda3/bin/python)中运行 还有/usr/bin/python和/usr/bin/python3(但这些没有被使用,因为大部分工作都是在Jupyter的终端上完成的)

Fix

在木星的终端:

所以cp / usr / lib64 libssl。10 . anaconda3 / lib / libssl如此。1 . 0 0

所以cp / usr / lib64 libcrypto。10 . anaconda3 / lib / libcrypto如此。1 . 0 0

是什么引发了这一切?

所以,这一切都在工作,直到我尝试做一个conda安装conda锻造

我不知道发生了什么,但conda一定更新了openssl的盒子(我猜),所以在这之后,一切都崩溃了。

基本上,我不知道,conda已经更新了openssl,但不知怎么地删除了旧的库,并用libssl.so.1.1和libcrypt .so.1.1替换了它。

我猜,Python3被编译为查找libssl.so.1.0.0

最后,诊断的关键是:

import ssl;打印(ssl.OPENSSL_VERSION)”

给出提示库“libssl.so.1.0.0”未找到

我做了一个很大的假设,即ssl的yum版本与conda版本相同,因此只要重命名共享对象就可以工作,事实也确实如此。

我的另一个解决方案是重新编译python,重新安装anaconda等等,但最后我很高兴我不需要这样做。

希望这能帮到你们。

我在OSX 10.11上遇到了类似的问题,因为在3.6之上安装了python 3.7的memcached。

警告:pip配置了需要TLS/SSL的位置,但是Python中的SSL模块不可用。

花了几个小时解链接openssl,重新安装,改变路径。但一切都无济于事。将openssl版本从旧版本更改为旧版本,做到了这一点:

brew switch openssl 1.0.2e

我在网上没有看到这个建议。希望它能为某人服务。