pip 安装/升级失败并出现 SyntaxError

Div*_*dia 6 python pip

我要升级pip

$ pip install --upgrade pip
Run Code Online (Sandbox Code Playgroud)

我得到这个失败输出。

$ 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-FErPSL/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-FErPSL/pip/
You are using pip version 8.1.2, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Run Code Online (Sandbox Code Playgroud)

这里需要做什么?使用 pip 升级/安装任何软件包也建议升级 pip 版本...但由于此原因升级失败...

我尝试过以下操作但没有成功

$  sudo python3 -m pip install -U pip
$  sudo python3 -m pip install -U setuptools
Run Code Online (Sandbox Code Playgroud)

看起来我在 /bin/python 和 /bin/python3 中有两个 python 安装

python --版本 Python 2.7.5

python3 --版本Python 3.6.8

小智 17

可以尝试执行以下命令\xef\xbc\x9a

\n
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py\npython get-pip.py\npip install --upgrade setuptools\n
Run Code Online (Sandbox Code Playgroud)\n

https://me.jinchuang.org/archives/1158.html

\n


Die*_*rez 3

您的 Python 版本似乎低于 3.6。Pip 在其最新版本中引入了新语法,因此从旧 Python 升级应该会失败。

从你发布的输出中,我看不出你的Python版本是哪个。那么我将针对以下情况为您提供解决方案:

  1. 您的 Python 版本低于 3.6。Pip 已放弃对您的 Python 版本的支持。我建议你升级你的Python版本。另外,您可以继续使用旧的 pip(如果您确实需要旧的 Python)。

  2. 你有更新的 Python 版本吗?也许您安装了许多版本的 Python。验证一下。