Python pip 无法确认 SSL 证书:SSL 模块不可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44290926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:52:38  来源:igfitidea点击:

pip cannot confirm SSL certificate: SSL module is not available

pythonraspberry-pipip

提问by MortenMoulder

I am trying to install RPi.GPIO for Python 3.6 on my Raspberry Pi Zero W, but somehow it won't connect to the python.org website. I have pip installed for 2.7, 3.0, and 3.6 installed, so when I go and do something like:

我正在尝试在我的 Raspberry Pi Zero W 上为 Python 3.6 安装 RPi.GPIO,但不知何故它无法连接到 python.org 网站。我已经为 2.7、3.0 和 3.6 安装了 pip,所以当我去执行以下操作时:

sudo pip3.6 install RPi.GPIO

I get this error:

我收到此错误:

pi@raspberrypi:~ $ sudo pip3.6 install RPi.GPIO
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting RPi.GPIO
  Could not fetch URL https://pypi.python.org/simple/rpi-gpio/: 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 RPi.GPIO (from versions: )
No matching distribution found for RPi.GPIO

pi@raspberrypi:~ $ sudo pip3.6 install RPi.GPIO
pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用。
收集 RPi.GPIO
  无法获取 URL https://pypi.python.org/simple/rpi-gpio/:确认 ssl 证书时出现问题:无法连接到 HTTPS URL,因为 SSL 模块不可用。- 跳过
  找不到满足 RPi.GPIO 要求的版本(来自版本:)
没有找到 RPi.GPIO 的匹配分布

I did try sudo apt-get install openssland so on, but it still doesn't work. I can access the website perfectly on my desktop and phone, but my Raspberry Pi won't at all. Any idea what I can do?

我确实尝试过sudo apt-get install openssl等等,但它仍然不起作用。我可以在台式机和手机上完美访问该网站,但我的 Raspberry Pi 根本无法访问。知道我能做什么吗?

回答by Colwin

Beforeinstalling python 3.6 you need to install the libraries needed.

安装 python 3.6之前,您需要安装所需的库。

sudo apt-get install build-essential checkinstall 
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

Do you have these installed on the PI?

你在 PI 上安装了这些吗?

More details here

更多细节在这里

回答by michaelfeng

I encounter the same problem,finally I solved it by following

我遇到了同样的问题,最后我通过以下方式解决了

  1. Check whether the openssl-devel has been installed. My OS is centos6 and the installing command is as following

    yum install openssl-devel -y

  2. Edit python source configure file

    vi /{yourpythonsource}/Modules/Setup

  1. 检查 openssl-devel 是否已经安装。我的操作系统是centos6,安装命令如下

    yum 安装 openssl-devel -y

  2. 编辑python源配置文件

    vi /{yourpythonsource}/Modules/Setup

. Uncomment some of content as following

. 取消注释部分内容如下

# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c



# Socket module helper for SSL support; you must comment out the other 
# socket line above, and possibly edit the SSL variable: 
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

recompile python.

重新编译python。

cd /{yourpythonsource}
make && make install

Now pip3 should be ok.

现在 pip3 应该没问题了。