pip is configured with locations that require TLS/SSL问题

Posted zwj-linux

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pip is configured with locations that require TLS/SSL问题相关的知识,希望对你有一定的参考价值。

linux 6 安装python3.7后,使用pip命令出现问题,提示找不到ssl模块,出现错误如下

# pip list
Package Version
---------- -------
pip 10.0.1
setuptools 39.0.1
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

pip版本

# pip --version
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
# pip list
Package    Version
---------- -------
pip        10.0.1 
setuptools 39.0.1 
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

 

经百度查询,系统centos6.5后,其中openssl的版本为

# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013

而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3.7.0。yum 安装的openssl 版本都比较低。

 

升级openssl

下载编译安装

# wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
...
# tar -zxvf openssl-1.1.1a.tar.gz
...
# cd openssl-1.1.1a 
# ./config --prefix=/usr/local/openssl no-zlib
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1a (0x1010101fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   Troubleshooting section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
[root@centos6 openssl-1.1.1a]# echo $?
0
# make && make install

备份原配置文件

# mv /usr/bin/openssl /usr/bin/openssl.bak
# mv /usr/include/openssl/ /usr/include/openssl.bak

新版设置

# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
# ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
# ln -s  /usr/local/openssl/bin/openssl /usr/bin/openssl

修改系统配置,写入openssl库文件的搜索路径

# echo /usr/local/openssl/lib >> /etc/ld.so.conf

使修改后的/etc/ld.so.conf生效

# ldconfig -v

查看版本

# openssl version
OpenSSL 1.1.1a  20 Nov 2018

 

需要重新编译安装python

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

 

再次使用pip

# pip list
Package    Version
---------- -------
pip        10.0.1 
setuptools 39.0.1 
You are using pip version 10.0.1, however version 19.3.1 is available.
You should consider upgrading via the pip install --upgrade pip command.

升级pip

# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 13kB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-19.3.1

 

尝试pip安装

# pip install matplotlib
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ReadTimeoutError("HTTPSConnectionPool(host=pypi.org, port=443): Read timed out. (read timeout=15)"): /simple/matplotlib/
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/61/42/3e92d7aa64295483fbca20a86c89b34d0cb43cffaadaffe028793902d790/matplotlib-3.1.2-cp37-cp37m-manylinux1_x86_64.whl (13.1MB)
     |                                | 30kB 4.9kB/s eta 0:44:56ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 425, in _error_catcher

可以下载安装,只是我的网络不行,下载不了。。

 

以上是关于pip is configured with locations that require TLS/SSL问题的主要内容,如果未能解决你的问题,请参考以下文章

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not 解决方法(

搭建docker-python环境时提示WARNING: pip is configured with locations that require TLS/SSL, however the ssl

搭建docker-python环境时提示WARNING: pip is configured with locations that require TLS/SSL, however the ssl(

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no

Configuration ‘androidTestCompile‘ is obsolete and has been replaced with ‘androidTestImplementation

configure: error: /usr/include/openssl is a bad --with-openssl prefix