sudo-H做什么?

2024-04-26 13:58:47 发布

您现在位置:Python中文网/ 问答频道 /正文

在尝试用pip安装virtualenv之后

$ pip install virtualenv

我有一个被拒绝的许可错误

IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'

所以我用sudo安装了virtualenv

$ sudo pip install virtualenv

但随后出现了一个警告:

The directory '/Users/petertao/Library/Caches/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 '/Users/petertao/Library/Caches/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的-H标志做什么?


Tags: installpiporandthevirtualenvlibrarysudo
1条回答
网友
1楼 · 发布于 2024-04-26 13:58:47

一般

^{}(确切的文本可能会有所不同,但会相似):

-H

The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.

为什么这是一个选择? 通常使用“sudo”不会更改$HOME环境变量。

例如:

 echo $HOME $USER
/home/testuser testuser

 sudo bash -c 'echo $HOME $USER'
/home/testuser root

 sudo -H bash -c 'echo $HOME $USER'
/home/root root

您可以看到,一个普通的sudo将我是哪个用户从“testuser”更改为“root”,而不是将$HOME设置为什么,而sudo-H还将变量从“my”HOME目录更改为root的HOME目录。

对你来说

pip警告您,它是以用户根用户身份执行的,并希望修改$HOME中的内容,而$HOME被设置为'/Users/petertao',它不属于根用户(很可能是“petertao”用户)。 此警告表示pip使用$HOME缓存文件,但由于文件夹所有权不一致,已禁用其自己的缓存。

当然,当以根pip执行时,可以修改'/Users/petertao/Library/Caches/pip',因为根几乎是万能的。 这以后可能会变得很麻烦,因为没有根目录运行的程序无法再覆盖或修改这些文件。 相反,pip拒绝写入另一个用户拥有的目录。

相关问题 更多 >