文章转自:http://blog.csdn.net/qq_25560423/article/details/62055497,其中有点小修改
python安装完毕后,提示找不到ssl模块:
例如这样:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting xxx
Could not fetch URL https://pypi.python.org/simple/xxxx/: 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 xxx (from versions: )
No matching distribution found for xxx
[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 “”, line 1, in
File “/usr/local/python27/lib/python2.7/ssl.py”, line 60, in
import _ssl # if we can’t import it, let the error propagate
ImportError: No module named _ssl
查看openssl安装包,发现缺少openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
[root@localhost ~]#
python pip安装模块。yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y
查看安装结果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
重新编译python
修改Setup文件
vi /usr/software/Python-2.7.5/Modules/Setup
修改成下面:
Socket module helper for socket(2)
_socket socketmodule.c timemodule.cSocket module helper for SSL support; you must comment out the othersocket 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
重新编译
make
make install
测试,已可正常使用。
[root@localhost ~]# python2.7.5
Python 2.7.5 (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
(1)、首先,make clean
python3中利用pip安装, (2)、使用./configure --prefix=/usr/local/python2.7.5 --enable-shared CFLAGS=-fPIC ,配置好,此时python将安装 到/usr/local/python2.7.5目录中。
(3)、执行make后,没错再执行make install,当然你setup文件关于ssl的注释掉的要打开,也就是上面修改setup文件的 那 一步。
(4)、如果测试ssl还没安装上的话,可以重新链接一下python的软链接和pip的软链接。
此时,再次使用pip命令重新安装部署所需库即可安装上了。
注:上面的方法不能用的话,请参考下面的文章:https://blog.csdn.net/qq_23889009/article/details/100887640
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态