pip install 报语法错误

近期发现pip2在升级某些模块的时候会发生一些语法错误,基础pip基础版本是8.1.2

[root@controller ~]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

报错如下:

[root@controller ~]# pip install -U setuptools
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/db/e2/c0ced9ccffb61432305665c22842ea120c0f649eec47ecf2a45c596707c4/setuptools-57.4.0.tar.gz (2.1MB)
    100% |████████████████████████████████| 2.2MB 409kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "setuptools/__init__.py", line 16, in <module>
        import setuptools.version
      File "setuptools/version.py", line 1, in <module>
        import pkg_resources
      File "pkg_resources/__init__.py", line 1367
        **raise SyntaxError(e) from e**
                                ^
    SyntaxError: invalid syntax
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-c_nNEz/setuptools/
You are using pip version 8.1.2, however version 21.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

[root@controller ~]# pip install -U pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/83/37/3f344e392de7792748ee32e05d7dd6f867eb2166c21c8711280fb30e2128/pip-21.2.2.tar.gz (1.6MB)
    100% |████████████████████████████████| 1.6MB 495kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-vfp8qV/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-vfp8qV/pip/
You are using pip version 8.1.2, however version 21.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

初步怀疑pip21有较大升级,较低版本升级有可能报错。所以先手动升级到pip20,然后在升级到最新的pip21.

手动下载pip20的Python安装包
[root@controller pip-20.2.4]# wget https://files.pythonhosted.org/packages/0b/f5/be8e741434a4bf4ce5dbc235aa28ed0666178ea8986ddc10d035023744e6/pip-20.2.4.tar.gz
解压
[root@controller pip-20.2.4]# tar -xvf pip-20.2.4.tar.gz 
手动安装
[root@controller pip-20.2.4]# python setup.py  install
升级到最新版本
[root@controller pip-20.2.4]# pip install -U 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.
Collecting pip
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 341 kB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.4
    Uninstalling pip-20.2.4:
      Successfully uninstalled pip-20.2.4
Successfully installed pip-20.3.4

升级到pip20最新版本后,有一个提示:Python2的环境最高支持pip20,pip21已经不再支持python2.7
在这里插入图片描述

  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值