python3中pip3安装出错,找不到SSL

最后更新于 2020-05-15 1264 次阅读

转载自刘伟的博客

最近在centos6.6上安装Python3.7之后,使用pip命令出现了问题,提示说找不到ssl模块,出现错误如下:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Could not fetch URL https:*******: There was a problem confirming the ssl certificate: 
Can't connect to HTTPS URL because the SSL module is not available. - skipping

本人安装Python3.7的操作如下:

1.wget获取安装包:
    wget http://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

2.解压安装包:
    tar -xvzf Python-3.7.0.tgz

3.检查安装平台属性,系统是否有编译时所需要额库,以及库的版本是否满足编译需要
    ./configure

4.编译源码
    make

5.成功编译之后,安装
    sudo make install

在安装完之后,我们希望用pip3命令来安装numpy。首先,用如下命令安装pip3:

sudo install python3-pip

安装完之后,使用pip3安装numpy:

sudo pip install python-numpy

但是此时就出错了,显示本文开始提到的错误,大致意思就是安装过程需要SSL,但是那个SSL找不到。

本人查阅网上资料,发现openSSL是系统自带的,所以一定是安装了的,本人用以下命令尝试再次安装openssl:

sudo apt-get install openssl
sudo apt-get install libssl-dev

但是安装结果显示是对其进行更新(update),这说明系统已经安装了openssl。但是pip3就是找不到ssl模块。

本人进入python3中,然后进行ssl导入操作:

import ssl

结果出错,错误如下:

no moudle named _ssl

显示没有ssl模块。本人再进入python中(即系统自带的python2.7中),进行ssl导入操作:

import ssl

发现并没有显示错误,导入正常。这说明openssl已经安装了,只是python2可以调用,新安装的python3却不能调用。

本人查阅资料发现,在./configure过程中,如果没有加上–with-ssl参数时,默认安装的软件涉及到ssl的功能不可用,刚好pip3过程需要ssl模块,而由于没有指定,所以该功能不可用。

解决办法是重新对python3.6进行编译安装,用一下过程来实现编译安装:

cd Python-3.6.2
./configure --with-ssl
make
sudo make install

这样就允许安装的python3使用ssl功能模块,进入python3中,执行import ssl发现未出错,正常再次调用pip3指令来安装numpy,发现正常,问题解决!


经上述后还是SSL出错,后又在chief_victo的博客找到另一个办法。结果失败。

安装Python3.7.0


提示找不到SSL模块

python安装完毕后,提示找不到ssl模块:

[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 11:08:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>

重新编译python(去掉最后4行的注释)

#修改Setup文件
 
vi /root/Python-3.6.5/Modules/Setup.dist
 
#修改结果如下:
 
# 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

 编译安装

./configure --prefix=/usr/local/python
 
make
 
make install
 测试,还是不正常。
[root@localhost ~]# python
 
Python 3.6.4 (default, Jun 3 2013, 14:56:13)
 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
 
Type "help", "copyright", "credits" or "license" for more information.
 
>>> import ssl
 
>>>

结果我的问题还是不是这个。

我的原因死OpenSSL版本太老了,需要安装最新的版本。安装好后python3.7还是不能识别最新的openssl,最后我屈服了,我重装系统到最新的centos7.5.

这是一次失败的体验!

此作者没有提供个人介绍
最后更新于 2020-05-15
查看评论 - NOTHING

Comments NOTHING

暂无评论

Markdown Supported while Forbidden

comment_user_avatar