当前位置:   article > 正文

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

python3.11 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一直报错:

  1. pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  2. Collecting numpy
  3. 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/
  4. 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/
  5. 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/
  6. 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/
  7. 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/
  8. 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
  9. Could not find a version that satisfies the requirement numpy (from versions: )
  10. No matching distribution found for numpy
  11. pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
  12. 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. 1.下载openssl
  2. wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
  3. tar -zxvf openssl-3.0.7.tar.gz
  4. cd openssl-3.0.7
  5. 2.编译安装
  6. ./config --prefix=/usr/local/openssl
  7. make
  8. make install
  9. # 3.备份原配置
  10. mv /usr/bin/openssl /usr/bin/openssl.bak
  11. mv /usr/include/openssl/ /usr/include/openssl.bak
  12. # 4.新版配置
  13. ln -s /usr/local/openssl/include/openssl /usr/include/openssl
  14. ln -s /usr/local/openssl/lib64/libssl.so.3 /usr/local/lib64/libssl.so
  15. ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
  16. # 5.修改系统配置
  17. ## 写入openssl库文件的搜索路径
  18. echo "/usr/local/openssl/lib64" >> /etc/ld.so.conf
  19. ## 使修改后的/etc/ld.so.conf生效
  20. ldconfig -v
  21. # 6.查看openssl版本
  22. 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:

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

这时再次执行:

pip3 install numpy

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/636024
推荐阅读
相关标签
  

闽ICP备14008679号