在服务器上安装了Python后使用pip安装cx_Oracle模块时发现无法安装。报错如下:
************************************************************
You are running Setuptools on Python 2, which is no longer
supported and
>>> SETUPTOOLS WILL STOP WORKING <<<
in a subsequent release (no sooner than 2020-04-20).
Please ensure you are installing
Setuptools using pip 9.x or later or pin to `setuptools<45`
in your environment.
If you have done those things and are still encountering
this message, please follow up at
https://bit.ly/setuptools-py2-warning.
************************************************************
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)': /simple/cx-oracle/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)': /simple/cx-oracle/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)': /simple/cx-oracle/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)': /simple/cx-oracle/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)': /simple/cx-oracle/
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/cx-oracle/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/cx-oracle/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)) - skipping
ERROR: Could not find a version that satisfies the requirement cx_Oracle (from versions: none)
ERROR: No matching distribution found for cx_Oracle
仔细看了一眼:Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),)
就是这里的问题:SSLError,证书验证失败。就是证书不受信任呗。
百度了一下得到以下的解决方案:
修改pip配置文件:
在windows下的路径为: [用户文件夹]/pip/pip.ini
其他系统为:[用户文件夹]/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple # 设置下载源为清华 加速下载
trusted-host = pypi.tuna.tsinghua.edu.cn # 信任这个地址,就免去了SSL验证
disable-pip-version-check = true # 设置不检查版本
timeout = 120 # 超时时长
[list]
format = columns # 设置使用pip config list命令时输出的样式
其中解决这次问题的关键就是trusted-host = pypi.tuna.tsinghua.edu.cn
需要注意的是:root用户设置好之后其他用户是不生效的。其他用户在使用的时候可以用sudo pip install xxx
来安装。或者在本用户的家目录下也创建pip.conf文件,并添加相应的配置。
最后,百度到的解决方案来自:https://blog.csdn.net/true1cc/article/details/102612629