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 b
sudo dscl . -append /Groups/wheel wheel $(whoami)
chmod -R 775 ${this_is_your_python_package_path}
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'
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
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
pip install --user <package name>
(no sudo needed) worked for me for a very similar problem.
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
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.