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

首先切换到 root 账户

1
su

安装 python3

1
apt install python3

安装 pip for python3

1
apt install python3-pip

更新 pip

1
python3 -m pip install --upgrade pip

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

1
2
3
4
5
root@LANCE-8700K:~# 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 更换了入口函数

1
vim /usr/bin/pip3

修改为

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/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 ,发现已经完美修复

Licensed under CC BY-NC-SA 4.0
最后更新于 Jan 07, 2019 12:54 UTC
使用 Hugo 构建
主题 StackJimmy 设计