Python3 ImportError: No module named _ssl解决方法

 

系统没有openssl,手动安装openssl
1.下载openssl,地址为http://www.openssl.org/source/openssl-1.0.2a.tar.gz
2.安装:
tar -xzvf openssl-1.0.2a.tar.gz
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make && make install
 
3.在/usr/local目录下找到include目录
找到路径/usr/local/include,后面的步骤会用到这个路径
这目录下边是有openssl 文件的
[root@Linux local]# pwd
/usr/local
[root@Linux local]# ll 
drwxr-xr-x. 2 root  root 4096 11月 13 13:59 bin
drwxr-xr-x. 3 root  root 4096 11月 13 13:59 include
drwxr-xr-x. 2 root  root 4096 11月  1 2011 lib
drwxr-xr-x. 4 root  root 4096 11月 13 13:59 lib64
drwxr-xr-x. 2 root  root 4096 11月  1 2011 libexec
drwxr-xr-x. 2 root  root 4096 11月  1 2011 sbin
 
 
4.在python3.x源文件里 Modules 找到Setup.dist文件,按如下步骤修改,使编译Python的时候能找到刚才安装的openssl的库
1)找到SSL相关配置
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#        -L$(SSL)/lib -lssl -lcrypto
 
2) 由于openssl是被安装在/usr/local目录下的lib64和include目录的不是安装在/usr/local/ssl目录,)把注释去掉,如下修改路径
SSL=/usr/local
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib64 -lssl -lcrypto

5 要重新安装编译 python3.x
./configure --prefix=/usr/local/xxxx
make && make install

6 试下是否可用

[root@iZbp1 Python-3.6.5]# python3
Python 3.6.5 (default, Mar 22 2019, 11:36:59) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 


参考 :https://blog.youkuaiyun.com/xiemanR/article/details/85224509

https://blog.youkuaiyun.com/zhengcaihua0/article/details/79681991

转载于:https://my.oschina.net/jack088/blog/3061907

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值