文章转自: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 ~]# -
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.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
-
重新编译
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
- 如果上面import ssl还是报错的话,可能是你重新编译安装python后,没有起作用,因为我之前在进行./configure的时候配置了安装的目录为/usr/local/python2.7.5,此时我们可以做下面的操作:
(1)、首先,make clean
(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