首页 > 解决方案 > 在我不是所有者的文件上使用 sudo chown 是否安全?

问题描述

我只是想 pip install beautifulsoup4 但是这样做我得到这个错误:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/beautifulsoup4-4.6.0.dist-info'
Consider using the `--user` option or check the permissions.

所以我这样做是为了检查谁“拥有”该文件,尽管这是我的个人笔记本电脑:

ls -l /Library/Python/2.7/site-packages and it returned this:
-rwxr-xr-x  1 root  wheel  157 Oct  7  2017 Extras.pth
-rw-r--r--  1 root  wheel  119 Oct  7  2017 README
-rw-r--r--  1 root  wheel  218 Jul 15 20:20 easy-install.pth
drwxr-xr-x  4 root  wheel  128 Jul 15 20:20 pip-10.0.1-py2.7.egg

所以我尝试仅使用以下内容将用户的所有权更改为此目录:

chown gaby:staff /Library/Python/2.7/site-packages

这被退回了:

chown: /Library/Python/2.7/site-packages: Operation not permitted

是因为我是 Macintosh HD 有一个单独的库文件,而用户意味着我,在用户文件中,不是“拥有”文件的根吗?如果是这样,这是否意味着我应该使用

sudo chown gaby:staff /Library/Python/2.7/site-packages

???这是安全的事情吗?如果我不在 Unix 上(我在 mac os 上),sudo 甚至会做任何事情吗?如果 site-packages 文件夹专门用于第三方软件包,我也很困惑为什么我什至会遇到这个问题。

提前致谢

标签: pythonterminalpermissionschown

解决方案


尝试sudo pip install beautifulsoup4或者最好使用virtualenv。您应该能够在不更改上述目录的权限的情况下执行其中任何一项。


推荐阅读