Is it acceptable and safe to run pip install under sudo?

后端 未结 6 963
时光说笑
时光说笑 2020-11-22 14:29

I\'ve started to use my Mac to install Python packages in the same way I do with my Windows PC at work; however on my Mac I\'ve come across frequent permission denied

6条回答
  •  一整个雨季
    2020-11-22 14:38

    Your original problem is that pip cannot write the logs to the folder.

    IOError: [Errno 13] Permission denied: '/Users/markwalker/Library/Logs/pip.log'
    

    You need to cd into a folder in which the process invoked can write like /tmp so a cd /tmp and re invoking the command will probably work but is not what you want.

    BUT actually for this particular case (you not wanting to use sudo for installing python packages) and no need for global package installs you can use the --user flag like this :

    pip install --user 
    

    and it will work just fine.

    I assume you have a one user python python installation and do not want to bother with reading about virtualenv (which is not very userfriendly) or pipenv.

    As some people in the comments section have pointed out the next approach is not a very good idea unless you do not know what to do and got stuck:

    Another approach for global packages like in your case you want to do something like :

    chown -R $USER /Library/Python/2.7/site-packages/
    

    or more generally

    chown -R $USER 
    

提交回复
热议问题