Linux上运行Python3程序运行报错:ModuleNotFoundError: no module named '_ssl'解决

2023-10-14 313点热度 0人点赞 0条评论

Linux上运行Python3程序的时候,报如下错误:

ModuleNotFoundError: no module named '_ssl'

或者pip3 install的时候,遇到如下错误:

pip is configured with locations that require tls/ssl
can't connect to https url because the ssl module is not available

原因是没有安装正确的openssl

首先确保安装了openssl11,如下:

yum install openssl11 openssl11-devel -y

cd /usr/local/openssl11 
ln -s /usr/lib64/openssl11 lib 
ln -s /usr/include/openssl11 include

重新编译装安装Python3,指定刚才安装的openssl11,如下:

cd /opt/
wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tgz
tar xvf Python-3.10.13.tgz
cd /opt/Python-3.10.13

./configure --enable-optimizations --with-openssl=/usr/local/openssl11
# --with-openssl=/usr/local/openssl11 也可以用如下替换配置,然后 ./configure --enable-optimizations
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
make altinstall

#测试是否成功
python3.10 -m ssl

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论