Python 如何在 MacOS High Sierra 上修复 Home-brew 的权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47513024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Fix Permissions on Home-brew on MacOS High Sierra
提问by Jonathan
When I tried to install python onto homebrew it downloaded it and then an error message popped up at the end that stopped it from completing. When I try to do it again it asks me to do:
当我尝试将 python 安装到自制软件时,它下载了它,然后在最后弹出一条错误消息,阻止它完成。当我再次尝试时,它要求我执行以下操作:
$ brew link python
After entering that the same error message appears:
输入后出现相同的错误消息:
permission denied @ dir_s_mkdir - /usr/local/lib
I have tried to do:
我试图做:
$ sudo chown -R $(whoami) /usr/local
And I get an error message that reads:
我收到一条错误消息,内容如下:
chown: /usr/local: Operation not permitted
chown: /usr/local: 不允许操作
回答by gfly
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew link python3
回答by Niquit
I tried and had this same ( I think ) output:
我试过并有同样的(我认为)输出:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
So I created a directory /usr/local/Frameworks as root, and than change the ownership:
所以我以 root 身份创建了一个目录 /usr/local/Frameworks,然后更改所有权:
sudo mkdir /usr/local/Frameworks && chown $USER:admin /usr/local/Frameworks
I tried again brew install python
:
我又试了一次brew install python
:
Warning: python 2.7.14 is already installed, it's just not linked.
You can use `brew link python` to link this version.
And then brew link python
:
然后brew link python
:
Linking /usr/local/Cellar/python/2.7.14... 26 symlinks created
Now in directory /usr/local/Frameworks/Python.framework/ I can see links, for example:
现在在目录 /usr/local/Frameworks/Python.framework/ 我可以看到链接,例如:
lrwxr-xr-x 1 niquit admin 62 Dec 8 21:41 /usr/local/Frameworks/Python.framework/Headers -> ../../Cellar/python/2.7.14/Frameworks/Python.framework/Headers/
lrwxr-xr-x 1 niquit admin 61 Dec 8 21:41 /usr/local/Frameworks/Python.framework/Python -> ../../Cellar/python/2.7.14/Frameworks/Python.framework/Python*
lrwxr-xr-x 1 niquit admin 64 Dec 8 21:41 /usr/local/Frameworks/Python.framework/Resources -> ../../Cellar/python/2.7.14/Frameworks/Python.framework/Resources/
In your case, I suggest create manually /usr/local/lib:
在你的情况下,我建议手动创建/usr/local/lib:
sudo mkdir /usr/local/lib && chown $USER:admin /usr/local/lib
A made a test by mv /usr/local/lib{,.orig}
, and I got:
A 做了一个测试mv /usr/local/lib{,.orig}
,我得到了:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/lib
Error: Permission denied @ dir_s_mkdir - /usr/local/lib
Like before I created manually directory sudo mkdir /usr/local/lib && chown $USER:admin /usr/local/lib
, and successful did brew link python
:
就像之前我手动创建目录一样sudo mkdir /usr/local/lib && chown $USER:admin /usr/local/lib
,成功做到了brew link python
:
Linking /usr/local/Cellar/python/2.7.14... 324 symlinks created
Now I can find some links:
现在我可以找到一些链接:
lrwxr-xr-x 1 niquit admin 54 Dec 8 22:01 python-2.7.pc -> ../../Cellar/python/2.7.14/lib/pkgconfig/python-2.7.pc
lrwxr-xr-x 1 niquit admin 50 Dec 8 22:01 python.pc -> ../../Cellar/python/2.7.14/lib/pkgconfig/python.pc
lrwxr-xr-x 1 niquit admin 51 Dec 8 22:01 python2.pc -> ../../Cellar/python/2.7.14/lib/pkgconfig/python2.pc
I think that Apple after latest update increased security, so its not possible to create now directory in /usr/ without root permission.
我认为 Apple 在最新更新后提高了安全性,因此无法在没有 root 权限的情况下在 /usr/ 中创建 now 目录。
回答by Shaul Hameed
sudo mkdir /usr/local/Frameworks
sudo chown $USER /usr/local/Frameworks
And then try re-installing python. This worked absolutely fine for me.
然后尝试重新安装python。这对我来说非常好。
回答by Chris
Run this, and follow its suggestions:
运行它,并遵循它的建议:
brew doctor
In my case, it wanted me to run:
就我而言,它希望我运行:
sudo mkdir -p /usr/local/sbin /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/sbin /usr/local/Frameworks
回答by H. Gourlé
/usr/local
can no longer be chown in High Sierra. Instead use
/usr/local
不能再在 High Sierra 中被 chown。而是使用
sudo chown -R $(whoami) $(brew --prefix)/*
回答by Bill Chan
In my case with MacOS 10.14 fresh installation in a new machine:
在我的情况下,MacOS 10.14 在新机器上全新安装:
brew doctor
And it suggests:
它表明:
sudo mkdir -p /usr/local/lib /usr/local/sbin
sudo chown -R $(whoami) /usr/local/lib /usr/local/sbin
回答by Walrus the Cat
Uninstalling and doing a clean install of homebrew will fix the issue.
卸载并全新安装自制软件将解决该问题。
回答by Johnny Chia
I reinstalled brew and fixed the issue.
我重新安装了 brew 并解决了这个问题。
to uninstall use the following command.
卸载使用以下命令。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
and to install brew again.
并再次安装 brew。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
回答by Tyler Kehrein
brew doctor
This command, as suggested by Chris above in the comments, solved almost ALL my home-brew issues running on a Mac Mini 2011 5,1 unofficially running MacOS Mojave. Simply enter that and follow all directions that terminal prints
正如上面 Chris 在评论中所建议的,这个命令几乎解决了我在非官方运行 MacOS Mojave 的 Mac Mini 2011 5,1 上运行的所有自制问题。只需输入并按照终端打印的所有说明进行操作
回答by user1747036
As mentioned, by henrikstroem, backticks can be helpful, and as mentioned by bnaecker special attributes might also hinder the process.
正如 henrikstroem 所提到的,反引号可能会有所帮助,正如 bnaecker 所提到的,特殊属性也可能会阻碍这个过程。
You might also try to run the command directly as root to see if better results, by doing sudo su -
and then chown -R username /usr/local
您也可以尝试直接以 root 身份运行该命令以查看是否有更好的结果,通过执行sudo su -
然后chown -R username /usr/local
But are you sure that is really what you want?
It might be more interesting to create a group that has an access on it (like chown -R originaluser:group /usr/local
, set the rights you want, and/or to make your user part of that group.
但你确定这真的是你想要的吗?创建一个具有访问权限的组可能更有趣(例如chown -R originaluser:group /usr/local
,设置所需的权限和/或使您的用户成为该组的一部分。