pip安装:请检查该目录的权限和所有者

问题:pip安装:请检查该目录的权限和所有者

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

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

因为我现在必须使用安装sudo

我的Mac上已经安装了python和一些库,我正在运行Yosemite。最近,我不得不进行彻底擦拭,然后重新安装操作系统。现在,我收到此提示,并且在弄清楚如何更改它时遇到了麻烦

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

我是这台计算机的唯一所有者,这是计算机上的唯一帐户。升级到python 3.4时,这似乎是个问题,似乎什么都没在正确的地方,virtualenv不会到达我期望的位置,等等。

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

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.

because I now have to install using 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

Before my command line was Parthenon$ now it’s 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.


回答 0

从运行pip到Windows时,我在Mac上也看到了这种变化sudo pip。添加-H到sudo会使该消息对我消失。例如

sudo -H pip install foo

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

因此,似乎pip正在调查,$HOME/Library/Log并且sudo默认情况下未将其设置$HOME/root/。毫不奇怪~/Library/Log,您是用户而不是root。

我怀疑这是最近的点差变化。我现在将其运行sudo -H以解决该问题。

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

sudo -H pip install foo

man sudo tells me that -H causes sudo to set $HOME to the target users (root in this case).

So it appears pip is looking into $HOME/Library/Log and sudo by default isn’t setting $HOME to /root/. Not surprisingly ~/Library/Log is owned by you as a user rather than root.

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


回答 1

这里的问题是,您以某种方式将其安装到virtualenv中sudo。可能是偶然的。这意味着root用户将重写Python软件包数据,从而使所有文件均由root拥有,而您的普通用户将无法再写入这些文件。通常,virtualenv仅应由普通的UNIX用户使用和拥有。

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

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

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

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

What is the problem here is that you somehow installed into virtualenv using sudo. Probably by accident. This means root user 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.

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

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

then pip should be able to write those files again.

More information about UNIX file permission management


回答 2

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

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


回答 3

基本信息

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

钥匙

  1. 将当前帐户添加到车轮组
sudo dscl . -append /Groups/wheel wheel $(whoami)
  1. 将python封装模式修改为775。
chmod -R 775 ${this_is_your_python_package_path}

整个东西

  • 当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'
  • 所以我cd /usr/local/python3/lib/python3.6/site-packages,然后ls -al得到:
drwxr-xr-x    6 root   wheel   192B  2 27 18:06 requests/

当我看到此消息时,我了解到,makedirs是写操作,但是drwxrwxr-x只有用户root才能显示的请求模式才能写入请求文件。如果将yutou(whoami)添加到组合轮,然后将包修改为组合轮可以写,那么我可以写,并且问题解决了。

如何在组轮中添加yutou?+检测车轮sudo dscl . -list /groups GroupMembership,,您会发现:

wheel                    root

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

wheel                    root yutou

修改python包模式

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

basic info

  • system: mac os 18.0.0
  • current user: yutou

the key

  1. add the current account to wheel group
sudo dscl . -append /Groups/wheel wheel $(whoami)
  1. modify python package mode to 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 requests and got:
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 -al and got:
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-x displaied 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.

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

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:

wheel                    root yutou

modify the python package mode

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

回答 4

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

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