Centos7安装python3.7.6报错:No module named _ssl 无敌终极解决方案

在centos7.6中安装python3.7.6时,能安装成功,但在运行gunicorn时会提示

No module named _ssl

尝试在python中导入ssl包,但还是报错找不到_ssl

经过九九八十一难,终于解决了

# 安装新版本openssl
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g
./config --prefix=/usr/local/openssl
make && make install
ln -s /usr/local/openssl/bin/openssl  /usr/local/bin/openssl
cp -r /usr/local/bin/openssl /usr/bin/
openssl version -a

重新编译python3.7.6,进入python3的源码目录:

vi Modules/Setup

按/查找_ssl,将如下部分代码的注释#去掉,wq保存,配置一定要是自己的openssl执行文件路径(默认是/usr/local/ssl,我这里修改了成SSL=/usr/local/openssl

# Socket module helper for socket(2)
_socket socketmodule.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/openssl
_ssl _ssl.c \
         -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
         -L$(SSL)/lib -lssl -lcrypto

改完之后再进行编译安装:

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make && make install

然后进入python,尝试导入ssl,成功!!!
其他版本的python按道理都是这样处理,有问题可随时评论交流!

你可能感兴趣的:(python,centos,_ssl,ssl,python,centos)