Sys.stderr.write(f"ERROR: {exc}") appears after upgrading pip

created at 08-31-2021 views: 237

Recently, when using pip on ubuntu16.04, it prompts to upgrade, and an error is reported after the upgrade.

Traceback (most recent call last):
 File "/home/brian/.local/bin/pip3", line 7, in <module>
   from pip._internal.cli.main import main
  File "/home/brian/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

solution

Find the corresponding python version on https://bootstrap.pypa.io/pip/ and click to get the following picture:

 corresponding python version

Right-click on the file and select copy link address;
Execute on the terminal of ubuntu16.04 for python3:

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

the same for python2:

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

PS: Because the get-pip.py obtained by python2 and python3 wget has the same name, the system will name the second downloaded get-pip.py as get-pip.py.1, and run it directly with the corresponding version of python.

created at:08-31-2021
edited at: 08-31-2021: