python3.11安装, 解决pip is configured with locations that require TLS/SSL问题

系统:centos7.4(虚拟机)

python版本:本机自带的2.7.5,以及参考python安装的python3.11

pip版本:本机自带的8.1.2,参考pip安装&升级升级到了20.3.4,pip3版本为22.3.1

openssl版本:本机自带的1.0.2k-fips(这里是个坑)

报错原因是,想通过下面的命令下载安装numpy包:

pip3 install numpy

在此之前用pip命令是可以的:

pip install numpy

但pip3一直报错:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting numpy
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.")': /simple/numpy/
Retrying (Retry(total=3, 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.")': /simple/numpy/
Retrying (Retry(total=2, 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.")': /simple/numpy/
Retrying (Retry(total=1, 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.")': /simple/numpy/
Retrying (Retry(total=0, 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.")': /simple/numpy/
Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

原因:系统版本centos7.4,其中openssl的版本为OpenSSL 1.0.2k-fips,而python3.11需要的openssl的版本为1.1.x及以上,需要对openssl进行升级,并重新编译python3.11(yum 安装的openssl 版本都比较低)。

升级openssl:

1.下载openssl
wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
tar -zxvf openssl-3.0.7.tar.gz
cd openssl-3.0.7

2.编译安装
./config --prefix=/usr/local/openssl 
make
make install

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

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

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

# 6.查看openssl版本
openssl version

如果这里openssl version 提示:

 /usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

诸如此类的错误,是由于建立软链接时第一个路径不是openssl的安装路径,请根据自己的openssl安装路径确认建立软链接的的第一个路径。

重新安装python3.11:

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

这时再次执行:

pip3 install numpy

仍然无法下载,参考原因是源的问题,换成了国内的pip源就可以正常安装了,使用如下命令即可:

pip3 install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

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