我使用的是 Windows 10 Pro,使用来自官方商店的 Linux 子系统和 Ubuntu 18.04“应用程序”。
问题:
$ sudo pip install ansible
The directory '/home/realtebo/.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.
请注意模块已成功安装,我的问题只是关于警告
我试过了
$ sudo rm /home/realtebo/.cache -rf
这删除了文件夹,但目录所有者的问题仍然存在
显然/home 是根目录
drwxr-xr-x 1 root root 512 Jul 25 23:01 home
但是/home/realtebo 是我的
drwxr-xr-x 1 realtebo realtebo 512 Aug 2 07:15 realtebo
你能解释一下问题的根源吗?
我应该以用户身份安装 pip 软件包而不是使用 sudo
吗?
最佳答案
问题或警告的根源在于您正在使用 sudo 以及 sudo 的工作方式安装 ansible。
Sudo 提升您的权限,以便您可以使用 root 权限安装软件包并执行操作。但是,这与 root 并不完全相同。 https://www.sudo.ws/
例如,如果您这样做
sudo su -
并进入完整的根 session ,然后执行
pip install ansible
那么警告就不会发生。
至于是否以用户身份安装软件包,而不是 sudo,或者甚至执行 sudo su - 并从 root session 安装,这取决于您想要如何工作和维护您的应用程序。 python环境。
理想情况下,您可能还想使用 virtualenv( https://virtualenv.pypa.io/en/stable/ )
关于Windows 10 上的 Ubuntu : pip cache folder not owned by current user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51646006/