Ubuntu sudo: pip:找不到命令
解决过程
1.vi命令编辑 /etc/sudoers 文件,将 Defaults env_reset ,改为 Defaults !env_reset
sudo vi /etc/sudoers
Defaults !env_reset
2.vi命令编辑.bashrc文件
sudo vi ~/.bashrc
在.bashrc文件中添加
alias sudo='sudo env PATH=$PATH'
添加完之后,再source一下
source ~/.bashrc
3.试试效果
fong@fong:~$ sudo pip install -U pip
The directory '/home/fong/.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/fong/.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.
Requirement already up-to-date: pip in ./anaconda3/lib/python3.5/site-packages (18.0)
fong@fong:~$
4.发现有两个用户权限的warning。提示是pip目录的属主不是sudo的root用户。如果必须用sudo pip,更改pip目录属主即可:
sudo chown root /home/fong/.cache/pip/http
sudo chown root /home/fong/.cache/pip
再试试
fong@fong:~$ sudo pip install -U pip
Requirement already up-to-date: pip in ./anaconda3/lib/python3.5/site-packages (18.0)
fong@fong:~$
Yes,You are done!