6

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

3
  • 1
    Somehow pip is using a low version of Python, but is trying to update to the lastest, but incompatible version. Weird. Which Python version are you trying to use? Commented Oct 25, 2021 at 15:02
  • 2
    maybe you have multiple versions of python that are causing this problem Commented Oct 25, 2021 at 15:02
  • 1
    Install the latest version of python and try to do it.This will help you phoenixnap.com/kb/upgrade-python Commented Oct 25, 2021 at 15:06

2 Answers 2

17

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I have the same python --version Python 2.7.5 but ran pip install --upgrade setuptools gives me this ` ^ SyntaxError: invalid syntax` . Any idea? Thank you
3

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.

3 Comments

$ python --version Python 2.7.5 $ python3 --version Python 3.6.8
I have dependencies on both python version.. how can I direct pip to use python3 instead?
Running python3 -m pip instead of pip works? Maybe python3.9 -m pip?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.