获取root用户的警告文件权限

这个警告意味着什么? 我在amazon ec2 Ubuntu 14.04 LTS实例上使用root执行以下命令时得到了它:

$ pip install https://github.com/troeger/opensubmit/archive/0.6.2.tar.gz The directory '/home/ubuntu/.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/ubuntu/.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. 

好吧,你的问题在报价中部分有答案:

您正在使用sudo获取root权限,但是您使用sudo方式不会调整$HOME的值,因此pip会尝试安装到调用sudo的用户的pip目录中。

如果实际用户想要删除或更改已安装的模块,这可能会导致问题,因此警告。

要避免警告,除非你不必,请使用不带root / sudo的pip或调用sudo作为sudo -H ,它将$HOME设置$HOME你要更改的用户,在本例中为/root

此消息暗示您可能先前使用sudo为当时发出的命令执行了pip。

例如

 sudo pip install https://github.com/troeger/opensubmit/archive/0.6.2.tar.gz 

默认情况下,sudo不会更改环境变量HOME ,因此不会更改sudo env | grep HOME sudo env | grep HOME正在打印HOME=/home/username 。 在-do命令中添加-H可以更改此行为,并打印HOME=/root

要解决您的问题,您应该确保此路径中的每个文件夹/home/ubuntu/.cache/pip/http (除了/和/ home)都归ubuntu

 sudo -H chown -R ubuntu: /home/ubuntu/.cache