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

前端 未结 5 1117
無奈伤痛
無奈伤痛 2020-11-28 01:12

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

相关标签:
5条回答
  • 2020-11-28 01:22

    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
    
    0 讨论(0)
  • 2020-11-28 01:33

    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

    0 讨论(0)
  • 2020-11-28 01:38

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

    0 讨论(0)
  • 2020-11-28 01:43

    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

    0 讨论(0)
  • 2020-11-28 01:46

    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.

    0 讨论(0)
提交回复
热议问题