centos7 python3.9.10 报错 No module named _ssl

首先安装依赖

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

配置openssl

tar -zxvf openssl-1.1.1v.tar.gz
cd openssl-1.1.1w/
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make
make install

mv /usr/bin/openssl /usr/bin/openssl_backup
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1

测试:

openssl version

 

配置python环境

tar -zxvf Python-3.9.10.tgz
cd Python-3.9.10.tgz/
./configure -C --with-openssl=/usr/local/openssl --with-openssl-rpath=auto --prefix=/usr/local/python39
make -j8
make altinstall
ln -s /usr/local/python39/bin/python3.9 /usr/bin/python39
ln -s /usr/local/python39/bin/pip3.9 /usr/bin/pip39

测试:

import ssl
print(ssl.OPENSSL_VERSION)

  

posted @ 2024-12-05 10:40  lvye001  阅读(14)  评论(0编辑  收藏  举报