Python PIP升级后执行命令报错: sys.stderr.write(f“ERROR: {exc}“)解决方法

近日在使用pip时终端始终提示

You are using pip version 8.1.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

于是手贱给升级了一下,然后再运行pip指令时始终产生如下报错

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

网上多位博主给出的解决方法是

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

但是该网址现在已经失效,执行如上指令后会得到开发者的一封信

Hi there!
 
The URL you are using to fetch this script has changed, and this one will no
longer work. Please use get-pip.py from the following URL instead:
 
    https://bootstrap.pypa.io/pip/2.7/get-pip.py
 
Sorry if this change causes any inconvenience for you!
 
We don't have a good mechanism to make more gradual changes here, and this
renaming is a part of an effort to make it easier to us to update these
scripts, when there's a pip release. It's also essential for improving how we
handle the `get-pip.py` scripts, when pip drops support for a Python minor
version.
There are no more renames/URL changes planned, and we don't expect that a need
would arise to do this again in the near future.
 
Thanks for understanding!
 
- Pradyun, on behalf of the volunteers who maintain pip.

尝试了各种方法之后,发现最佳的解决方法是

sudo easy_install pip==20.3.4

下载完成后,使用pip --version查看pip版本,即可看到版本为20.3.4,不会再产生报错。

参考链接:Python2.7 安装pip报错 sys.stderr.write(f"ERROR: {exc}")

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值