Ubuntu 16.04中卸载Anaconda引起的pip(pip3)异常

Ubuntu 16.04中卸载Anaconda引起的pip异常

    • 正确方法
    • 错误尝试

我在 ubuntu 系统中安装了支持python3.7版本的 Anaconda3 以及 conda 后由于python版本不匹配问题(tensorflow, opencv在python3.5中),将其卸载,但卸载后出现pip不能使用问题,在 pip install xxx 后错误提示如下:

~$ pip install matplotlib
bash: /home/cyq/.local/bin/pip: /home/cyq/anaconda3/bin/python: bad interpreter: No such file or directory

正确方法

首先给出亲测成功的解决方法:

  1. 删除原有的 pippip3

sudo apt-get remove python-pip
sudo apt-get remove python3-pip

  1. 重新安装 pippip3

sudo python -m pip install --upgrade --force-reinstall pip
sudo python3 -m pip install --upgrade --force-reinstall pip

显示如下:

~$ sudo python3 -m pip install --upgrade --force-reinstall pip
The directory ‘/home/caoyiqing/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
The directory ‘/home/caoyiqing/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 8.2kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-19.2.1

成功!
由于网络问题,这一步可能会报一大堆错,重复执行几次命令就可以了。
测试一下,输入 pip

~ $ pip

正确的输出如下(部分):

Usage:
pip [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

错误尝试

从一开始的提示中,可以看出是 pip 软链接问题。不过很遗憾没有找到 pip 命令执行的具体过程和使用的文件。在 /usr/.local/bin和/usr/bin 中找到了 pip和pip3 文件,不过很遗憾文件里没有相关路径。参考别人的博客,终端输入:

sudo gedit ~/.bashrc

将文件最低端的 conda 部分和 export PATH=/home/…/bin:$PATH 注册掉,保存并关闭文件。
在终端执行:

source ~/.bashrc

关闭终端,重启终端。
当然…失败了。个人认为可能是安装conda时自动更改了pip的执行文件,而这个执行文件很明显不是我们上面找到的这三个文件…

望指正

参考链接: http://www.mamicode.com/info-detail-2694327.html.

你可能感兴趣的:(Ubuntu 16.04中卸载Anaconda引起的pip(pip3)异常)