Ubuntu 更新 pip 后 pip 失效的解决方案

首先切换到 root 账户

su

安装 python3

apt install python3

安装 pip for python3

apt install python3-pip

更新 pip

python3 -m pip install --upgrade pip

更新完成后执行 pip3 会出现如下报错

[email protected]:~# pip3
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

原因是新版 pip 18.1 更换了入口函数

vim /usr/bin/pip3

修改为

#!/usr/bin/python3
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

再去尝试 pip3 ,发现已经完美修复

0 Comments (114 Views)

Leave a Reply

Your email address will not be published. Required fields are marked *