python错误ImportError: No module named _ssl(centos下)
python错误ImportError: No module named _ssl(centos下)
场景
安装好python之后,导入ssl模块报错: ImportError: No module named _ssl
解决办法
1.查看openssl,openssl-devel是否安装
rpm -qa|grep openssl
openssl-devel-1.0.1e-30.el6.x86_64
openssl-1.0.1e-30.el6.x86_64
下载rpm包
https://archive.kernel.org/centos-vault/6.6/os/x86_64/Packages/
或
链接:https://pan.baidu.com/s/1mP8SEghDekrSJesP7ZjB1g
提取码:nce2
openssl-devel-1.0.1e-30.el6.x86_64.rpm
zlib-devel-1.2.3-29.el6.x86_64.rpm
openssl-1.0.1e-30.el6.x86_64.rpm
krb5-devel-1.10.3-33.el6.x86_64.rpm
krb5-libs-1.10.3-33.el6.x86_64.rpm
keyutils-libs-devel-1.4-4.el6.x86_64.rpm
libcom_err-devel-1.41.12-18.el6.x86_64.rpm
libselinux-devel-2.0.94-5.3.el6_4.1.x86_64.rpm
pkgconfig-0.23-9.1.el6.x86_64.rpm
libsepol-devel-2.0.41-4.el6.x86_64.rpm
安装
rpm -ivh openssl-devel-1.0.1e-30.el6.x86_64.rpm
注:按照提示安装依赖包
或
强制安装、忽略依赖关系
rpm -ivh 包名 --force --nodeps
修改python文件
1.下载python源码包
wget https://registry.npmmirror.com/-/binary/python/3.6.8/Python-3.6.8.tgz
2.解压
tar -zxvf Python-3.6.8.tgz
3.修改文件
cd Python-3.6.8/
vim Modules/Setup.dist
如果没有Setup.dist文件则修改Setup
原文件内容:大概在 51% 的位置
#SSL=/usr/local/ssl
#_ssl _ssl.c \
# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
# -L$(SSL)/lib -lssl -lcrypto
修改为:把注释去了,修改SSL的路径
SSL=/usr/local/
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
4.重新安装python
在Python-3.6.8文件夹中输入命令:
./configure --prefix=/usr/local/python3
make
make install
运行
运行测试,正常。
![](https://img2020.cnblogs.com/blog/701393/202111/701393-20211103141014284-2068782946.png)