Python pip install: 请检查该目录的权限和所有者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27870003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:23:24  来源:igfitidea点击:

pip install: Please check the permissions and owner of that directory

pythonpipsudoosx-yosemite

提问by Phil Andrews

While installing pip and python I have ran into a that says:

在安装 pip 和 python 时,我遇到了一个说:

The directory '/Users/Parthenon/Library/Logs/pi' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.

目录“/Users/Parthenon/Library/Logs/pi”或其父目录不属于当前用户所有,并且调试日志已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 -H 标志。

because I now have to install using sudo.

因为我现在必须使用sudo.

I had python and a handful of libraries already installed on my Mac, I'm running Yosemite. I recently had to do a clean wipe and then reinstall of the OS. Now I'm getting this prompt and I'm having trouble figuring out how to change it

我的 Mac 上已经安装了 python 和一些库,我正在运行 Yosemite。我最近不得不做一个干净的擦拭,然后重新安装操作系统。现在我收到了这个提示,但我无法弄清楚如何更改它

Before my command line was Parthenon$now it's Philips-MBP:~ Parthenon$

之前我的命令行是Parthenon$现在Philips-MBP:~ Parthenon$

I am the sole owner of this computer and this is the only account on it. This seems to be a problem when upgrading to python 3.4, nothing seems to be in the right place, virtualenv isn't going where I expect it to, etc.

我是这台电脑的唯一所有者,这是它的唯一帐户。升级到 python 3.4 时,这似乎是一个问题,似乎没有合适的地方,virtualenv 没有达到我期望的地方,等等。

回答by Mikko Ohtamaa

What is the problem here is that you somehow installed into virtualenv using sudo. Probably by accident. This means rootuser will rewrite Python package data, making all file owned by root and your normal user cannot write those files anymore. Usually virtualenv should be used and owned by your normal UNIX user only.

这里的问题是您以某种方式使用sudo. 大概是意外吧。这意味着root用户将重写 Python 包数据,使 root 拥有的所有文件和您的普通用户无法再写入这些文件。通常,virtualenv 应该只由您的普通 UNIX 用户使用和拥有。

You can fix the issue by changing UNIX file permissions pack to your user. Try:

您可以通过将 UNIX 文件权限包更改为您的用户来解决此问题。尝试:

$ sudo chown -R USERNAME /Users/USERNAME/Library/Logs/pip
$ sudo chown -R USERNAME /Users/USERNAME/Library/Caches/pip

then pipshould be able to write those files again.

然后pip应该能够再次写入这些文件。

More information about UNIX file permission management

有关 UNIX 文件权限管理的更多信息

回答by Von

I also saw this change on my Mac when I went from running pipto sudo pip. Adding -Hto sudo causes the message to go away for me. E.g.

当我从跑步pipsudo pip. 添加-H到 sudo 会导致消息对我消失。例如

sudo -H pip install foo

man sudotells me that -Hcauses sudoto set $HOMEto the target users (root in this case).

man sudo告诉我-H导致sudo设置$HOME为目标用户(在这种情况下为 root)。

So it appears pip is looking into $HOME/Library/Logand sudoby default isn't setting $HOMEto /root/. Not surprisingly ~/Library/Logis owned by you as a user rather than root.

所以看起来 pip 正在调查$HOME/Library/Log并且sudo默认情况下没有设置$HOME/root/. 毫不奇怪~/Library/Log,您是作为用户而不是 root 拥有的。

I suspect this is some recent change in pip. I'll run it with sudo -Hfor now to work around.

我怀疑这是 pip 最近的一些变化。我会暂时运行它以sudo -H解决问题。

回答by Safwan

pip install --user <package name>(no sudo needed)worked for me for a very similar problem.

pip install --user <package name>(不需要 sudo)为我解决了一个非常相似的问题。

回答by kougazhang

basic info

基础信息

  • system: mac os 18.0.0
  • current user: yutou
  • 系统:mac os 18.0.0
  • 当前用户: yutou

the key

钥匙

  1. add the current account to wheel group
  1. 将当前帐户添加到轮组
sudo dscl . -append /Groups/wheel wheel $(whoami)
  1. modify python package mode to 775.
  1. 将python包模式修改为775。
chmod -R 775 ${this_is_your_python_package_path}

the whole thing

整个东西

  • when python3 compiled well, the infomation is just like the question said.
  • I try to use pip3 install requestsand got:
  • 当python3编译好时,信息就像问题所说的一样。
  • 我尝试使用pip3 install requests并得到:
File "/usr/local/python3/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 
'/usr/local/python3/lib/python3.6/site-packages/requests'
  • so i cd /usr/local/python3/lib/python3.6/site-packages, then ls -aland got:
  • 所以我cd /usr/local/python3/lib/python3.6/site-packages,然后ls -al得到:
drwxr-xr-x    6 root   wheel   192B  2 27 18:06 requests/

when i saw this, i understood, makedirs is an action of write, but the requests mode drwxrwxr-xdisplaied only user root can write the requests file. If add yutou(whoami) to the group wheel, and modify the package to the group wheel can write, then i can write, and the problem solved.

当我看到这个时,我明白了,makedirs 是一个写操作,但是请求模式drwxrwxr-x显示只有用户 root 可以写请求文件。如果把yutou( whoami)加到群轮,修改包到群轮可以写,那么我就可以写了,问题就解决了。

How to add yutou to group wheel? + detect group wheel, sudo dscl . -list /groups GroupMembership, you will find:

如何将鱼头添加到组轮?+ 检测组轮sudo dscl . -list /groups GroupMembership,,你会发现:

wheel                    root

the group wheel only one member root. + add yutou to group wheel, sudo dscl . -append /Groups/wheel wheel yutou. + check, sudo dscl . -list /groups GroupMembership:

组轮只有一个成员根。+ 将鱼头添加到组轮,sudo dscl . -append /Groups/wheel wheel yutou。+ 检查,sudo dscl . -list /groups GroupMembership

wheel                    root yutou

modify the python package mode

修改python打包方式

chmod -R 775 /usr/local/python3/lib/python3.6

回答by jeffhale

If you altered your $PATH variable that could also cause the problem. If you think that might be the issue, check your ~/.bash_profile or ~/.bashrc

如果您更改了也可能导致问题的 $PATH 变量。如果您认为这可能是问题所在,请检查您的 ~/.bash_profile 或 ~/.bashrc