Skip to content
本页目录

报错内容

pip install 三方包 出现locations that require TLS/SSL...报错

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /pypi/simple/aliyun-python-sdk-core/

问题原因

python3.11.x对openssl版本要求较高,需要openssl1.1.x 及以上

也可通过把安装源的https换成http

解决方法

1.1、重新安装openssl(升级openssl)

默认centos7.9.2009(cat /etc/redhat-release)的openssl版本(openssl version)为OpenSSL 1.0.2k-fips 26 Jan 2017,需要重新安装

#下载最新版openssl(下载较慢)
cd /tmp
wget https://www.openssl.org/source/openssl-3.1.2.tar.gz
tar -zxvf openssl-3.1.2.tar.gz
cd openssl-3.1.2

#编译安装(先创建/usr/local/openssl3目录)
./config --prefix=/usr/local/openssl3
make
make install
config编译时可能报错:Can't locate IPC/Cmd.pm in @INC (@INC contains: 。。。。缺少IPC/Cmd.pm模块
解决方法:yum -y install perl-IPC-Cmd

#备份原配置
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak

#新版配置
ln -s /usr/local/openssl3/include/openssl /usr/include/openssl
ln -s /usr/local/openssl3/lib64/libssl.so.3 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl3/bin/openssl /usr/bin/openssl

#写入openssl库文件的搜索路径
echo "/usr/local/openssl3/lib64" >> /etc/ld.so.conf
#使修改后的/etc/ld.so.conf生效
ldconfig -v

#查看openssl版本
openssl version

#查看openssl位置
which openssl

1.2、编译安装python3.11.x( 注意编译参数 --with-openssl )

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl3

make && make install

说明:如果使用宝塔项目管理器安装python则修改:

/www/server/panel/plugin/pythonmamager/install_python.sh

里的安装参数

其他问题

pip安装三方包如果出现SSL限制:使用 --trusted-host 参数

pip3 install package_name -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

镜像源


豆瓣 http://pypi.douban.com/simple/
中国科学技术大学http://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学http://pypi.hustunique.com/
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
山东理工大学:http://pypi.sdutlinux.org/

Released under the Apache License 2.0