pip升级错误有效解决方案 ImportError: cannot import name 'main'
这个问题一般是由pip从9.x.x版本往高版本升级导致的,主要原因是pip API功能上有修改但是pip文件升级后没有更新。按下文所述方法更改pip文件即可。
根据代码中提示的报错pip文件路径编辑
例如我的路径是/usr/bin/pip(pip2和pip3对应的路径就是pip2、pip3)
sudo gedit /usr/bin/pip
文件打开如下所示
#!/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())
修改代码倒数第三行和最后一行:
#!/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._internal import main
if __name__ == '__main__':
sys.exit(main.main())
保存后直接运行
pip --version
无报错即成功
问题解决,留个赞吧~