已解决,解决方法直接跳转到文章末尾
这个问题遇到过好几次了,尝试多种办法但都没解决,之前一次是在部署openstack时遇到,当时也是没解决。
使用linux自带到python2.7,pip版本只有6.x,需要升级pip,不能使用yum install pip,yum上的安装包太老了
[root@ansible pip]# pip -V
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
1. pip install --upgrade pip 无效
[root@ansible pip]# pip install --upgrade pip
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pip/
Collecting pip
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ba/19/e63fb4e0d20e48bd2167bb7e857abc0e21679e24805ba921a224df8977c0/pip-23.2.1.tar.gz (2.1MB)
100% |████████████████████████████████| 2.1MB 33.0MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-4qykuD/pip/setup.py", line 7
def read(rel_path: str) -> str:
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4qykuD/pip/
You are using pip version 8.1.2, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
2. pip install --upgrade pip -i http://pypi.tuna.tsinghua.edu.cn/simple/ 无效
提示证书有问题
[root@ansible pip]# pip install --upgrade pip -i http://pypi.douban.com/simple
The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host pypi.douban.com'.
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
You are using pip version 8.1.2, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
3. 改源后执行pip install --upgrade pip,提示ssl有问题,排除是源的问题。 改源其实就相当于-i URL,不用尝试 无效
[root@ansible pip]# cat /root/.config/pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
4. 添加参数--trusted-host pypi.tuna.tsinghua.edu.cn 无效
pip install --upgrade pip -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn 又回到第一个报错。
不行,跟pip install --upgrade pip一样报错。
5. python -m pip install --upgrade pip 同个报错 无效
python -m pip install --upgrade --force pip 同个报错 无效
6. python -m ensurepip --upgrade 未找到模块 无效
[root@ansible pip]# python -m ensurepip --upgrade
/usr/bin/python: No module named ensurepip
参考pip文档:https://pip.pypa.io/en/stable/installation/
**************************************************************************************************************
------------------------------------------------------有效 有效 有效-----------------------------------------------------
7. python get-pip.py 有效
Index of /pip/
[root@ansible pip]# python get-pip.py
python: can't open file 'get-pip.py': [Errno 2] No such file or directory
[root@ansible pip]# python
get-pip.py 提示要用2.7的get-pip.py,centos自带的是2.7,下载错了
[root@ansible opt]# wget https://bootstrap.pypa.io/get-pip.py
[root@ansible opt]# ls
frp get-pip.py k8s-prometheus-grafana-master k8s-prometheus-grafana-master.zip
[root@ansible opt]# python get-pip.py
ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7. Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead.
有用,pip更新到20.3.4版本
[root@ansible opt]# wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
[root@ansible opt]# ls
frp get-pip.py k8s-prometheus-grafana-master k8s-prometheus-grafana-master.zip
[root@ansible opt]# python get-pip.py
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. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
******
Successfully installed pip-20.3.4 wheel-0.37.1
[root@ansible opt]# pip -V
pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 2.7)
最后测试 pip install --upgrade pip ,终于不报错了
可能对于python2的pip版本最高只到20.3.4,而pip23是适用于python3的
[root@ansible opt]# pip install --upgrade pip
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. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (20.3.4)
测试安装模块requests
[root@ansible opt]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named requests
>>>
[3]+ Stopped python
[root@ansible opt]# pip install requests
******
Successfully installed certifi-2021.10.8 chardet-4.0.0 idna-2.10 requests-2.27.1 urllib3-1.26.16
[root@ansible opt]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
------------------------------------------------------有效 有效 有效-----------------------------------------------------
**************************************************************************************************************