pip install --upgrade pip失败修复记录 2021/12/01

环境:
ubuntu 16.04
python 2.7
pip 8.1.1

问题: pip install --upgrade pip失败

具体报错信息:

Collecting pip
  Using cached https://files.pythonhosted.org/packages/da/f6/c83229dcc3635cdeb51874184241a9508ada15d8baa337a41093fab58011/pip-21.3.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-KfOWy6/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-KfOWy6/pip/
You are using pip version 8.1.1, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

问题原因:
直接通过命令: pip install --upgrade pip 默认升级到最新pip版本21.3.1 (2021/12/01) 。
但 pip 21.0 之后的版本不支持python 2 ,所以导致升级失败。
在这里插入图片描述
参考 :
https://pip.pypa.io/en/stable/news/#id158

修复方法:
升级到最近一个pip 支持python2 的版本: 20.3.4
修改命令如下:

python -m pip install --upgrade pip==20.3.4

修改后可以正常更新

Collecting pip==20.3.4
  Downloading https://files.pythonhosted.org/packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 870kB/s 
Installing collected packages: pip
Successfully installed pip-20.3.4
You are using pip version 20.3.4, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

猜你喜欢

转载自blog.csdn.net/ever_who/article/details/121651060