系统centos7.4(虚拟机

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

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

openssl版本本机自带的1.0.2kfips这里是个坑)

报错原因是,想通过下面的命令下载安装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.2kfips,而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

原文地址:https://blog.csdn.net/weixin_41803458/article/details/128715977

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_26970.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注