Divyansh Hardia
Divyansh Hardia

Reputation: 99

pip install/upgrade fails with SyntaxError

I want to upgrade pip

$ pip install --upgrade pip

I get this failure output.

$ 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.

What needs to be done here? Upgrading/installing any package with pip also suggests that upgrade pip version... but upgrading fails due to this...

I have tried the following without success

$  sudo python3 -m pip install -U pip
$  sudo python3 -m pip install -U setuptools

Looks like I have two installations of python in /bin/python and /bin/python3

python --version Python 2.7.5

python3 --version Python 3.6.8

Upvotes: 6

Views: 27125

Answers (2)

jgh jj
jgh jj

Reputation: 181

You can try to execute the following commands:

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
pip install --upgrade setuptools

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

Upvotes: 17

Diego Ramirez
Diego Ramirez

Reputation: 679

It seems like you have a Python version lower than 3.6. Pip has introduced new syntax on its latest releases, so upgrading from an old Python should fail.

From the output you posted, I can't see which is your Python version. So I'll give you the solution for the following cases:

  1. You have a Python version lower than 3.6. Pip has dropped the support for your Python version. I recommend you to upgrade your Python version. Also, you can stay with and old pip (if you really need that old Python).

  2. You have a newer Python version? Maybe you have many versions of Python installed. Verify that.

Upvotes: 3

Related Questions