我从 pip ver 9 开始,在阅读了有关如何升级的博客后,我运行了以下命令,但似乎破坏了 pip:
# pip install --upgrade pip
这安装了 pip ver 18 !!
Successfully installed pip-18.0
此后,pip 将无法运行并出现以下错误:例如
# pip --version
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
i)我已删除 pip 并按如下方式重新安装,但没有成功:
# sudo apt-get remove python-pip
# sudo apt purge python-pip
# which pip
! pip is not found
# sudo apt install python-pip
从上面重新安装后,任何 pip 命令仍然失败并出现与之前相同的错误......
ii)我运行了此命令,它发现安装包仍然在系统上:
# python2.7 -m pip --version
pip 18.0 from /home/person/.local/lib/python2.7/site-packages/pip (python 2.7)
# ll /home/person/.local/lib/python2.7/site-packages/
<snip>
drwxr-xr-x 4 person person 4096 Aug 1 13:12 pip/
drwxr-xr-x 2 person person 4096 Aug 1 13:12 pip-18.0.dist-info/
问:如何恢复到 pip 版本 9.x?重新安装似乎不起作用?
问:我是否也必须删除 python2.7,然后重新安装两者(除非必要,否则我不想这样做)?
答案1
您也不必删除 python2.7。创建一个/home/person/.local/lib/python2.7/site-packages/pip
引用文件的符号链接/usr/bin/pip
。打开终端并输入:
sudo apt install python-pip # installs version 9.0.1
cd /home/person/.local/lib/python2.7/site-packages/
rm -r pip
which pip # check pip location
sudo ln -s /usr/bin/pip /home/person/.local/lib/python2.7/site-packages/pip # /usr/bin/pip may be /usr/local/bin/pip for some users
检查 pip 9.0.1 是否已安装。
python2.7 -m pip --version