python安装好后,提示找不到ssl模块

在CentOS系统中,遇到Python启动时报找不到_ssl模块错误。通过检查发现openssl已安装,但缺少openssl-devel。通过yum安装openssl-devel,然后修改Python源码文件Setup,重新编译并安装Python,成功解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.测试

[root@s011805161450 ~]# python

Python 2.7.8 (default, Jun 17 2016, 01:25:39) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] 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/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

2.查看

[root@s011805161450 ~]# yum list installed | grep ssl
openssl.x86_64          1.0.0-27.el6    @anaconda-CentOS-201303020151.x86_64/6.4

3.安装

[root@s011805161450 ~]# yum install openssl-devel -y

4.查看结果

[root@s011805161450 ~]# rpm -aq|grep openssl
openssl-1.0.1e-48.el6_8.1.x86_64
openssl-devel-1.0.1e-48.el6_8.1.x86_64

5.重新编译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

6.重新编译

make
make install

7.测试结果

[root@s011805161450 ~]# python
Python 2.7.8 (default, Jun 21 2016, 17:51:18) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _ssl
>>> exit()


转载请注明:转自http://write.blog.youkuaiyun.com/postedit/51725016

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值