45

Following the instructions on this page to install pip on python2 https://linuxhint.com/installing_pip_linux_mint/

It's failing at the last step, $ sudo python2 get-pip.py

with this error,

Traceback (most recent call last):
  File "get-pip.py", line 24226, in <module>
    main()
  File "get-pip.py", line 199, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    from pip._internal.cli.main import main as pip_entry_point
  File "/tmp/tmp2aZyDl/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

I've tried to look everywhere for a solution, but can't find one. What is it that I'm doing wrong?

Hsarp
  • 1,317
  • 1
  • 9
  • 11
  • 7
    The `f"some string {some_variable}"` is Python 3.6+ syntax, are you sure you're using the right `get-pip.py` for Python 2? – dogman288 Jan 24 '21 at 02:02
  • 2
    I'm not sure if I'm using the right ```get-pip.py```. According to the instructions on the webpage, I added the universe repository, ran apt update, installed python2, which I already had, and ran this command ```$ curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py```, followed by ```$ sudo python2 get-pip.py```. Maybe the get-pip has been overwritten by the file required for Python3? – Hsarp Jan 24 '21 at 02:07
  • 4
    They really need to update the instructions. The right file for python2 has been moved over to here, ```https://bootstrap.pypa.io/2.7/get-pip.py``` – Hsarp Jan 24 '21 at 02:10
  • See https://stackoverflow.com/a/65871131/7976758 – phd Jan 24 '21 at 13:43
  • Does this answer your question? [Python Pip broken wiith sys.stderr.write(f"ERROR: {exc}")](https://stackoverflow.com/questions/65896334/python-pip-broken-wiith-sys-stderr-writeferror-exc) – Peter O. Feb 08 '21 at 16:44

5 Answers5

84

The correct get-pip.py file for python2 has been moved to https://bootstrap.pypa.io/pip/2.7/get-pip.py

Naytzyrhc
  • 2,297
  • 26
  • 39
Hsarp
  • 1,317
  • 1
  • 9
  • 11
  • 1
    is there a way to update this to install python via `pyenv install py2.7.1.1` – Lycon Apr 29 '21 at 02:54
  • 4
    The new downloading location is correct but it gives the following error during the installation curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1863k 100 1863k 0 0 2637k 0 --:--:-- --:--:-- --:--:-- 2635k root@c0010-10213595-1:~# python get-pip.py ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none) ERROR: No matching distribution found for pip<21.0 – Ananda Subasinghe Jun 07 '21 at 04:57
16

PIP has dropped support for Python 2.7 in the result you are facing the above issue, so the only thing is to downgrade the version of pip.

only the following command worked for me...

sudo easy_install pip==20.3.4
gondaljutt
  • 681
  • 4
  • 15
10

This is what you need to do

wget https://bootstrap.pypa.io/2.7/get-pip.py
python get-pip.py
Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76
4

I was getting this error with pip. This command worked for me sudo easy_install pip==20.3.4

Shiva
  • 126
  • 9
3

Try installing previous version of get-pip

wget https://bootstrap.pypa.io/3.5/get-pip.py

python get-pip.py