在macOS High Sierra(10.13.6)
版本上,使用Homebrew
安装python2
的时候出现如下问题:
1 2 3 4 5 6 7 8 9 10 11 12 |
$ brew install python2 Warning: python@2 2.7.15_1 is already installed, it's just not linked You can use `brew link python@2` to link this version. $ brew link python@2 Linking /usr/local/Cellar/python@2/2.7.15_1... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks $ sudo brew link python@2 Password: Error: Running Homebrew as root is extremely dangerous and no longer supported. As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system. |
网上的解决方法是把整个/usr/local
的所有者修改为当前用户,但是新版本的macOS High Sierra(10.13.6)
已经不支持这样操作了,如下:
1 2 |
$ sudo chown -R `whoami` /usr/local chown: /usr/local: Operation not permitted |
那么解决方法如下:
1 2 3 4 5 6 7 |
$ sudo chown -R `whoami` /usr/local/Homebrew/ $ sudo chown -R $(whoami) $(brew --prefix)/* $ sudo mkdir /usr/local/Frameworks $ sudo chown -R `whoami` /usr/local/Frameworks/ |
完成上面的操作后,我们可以看到已经能成功操作了:
1 2 3 4 5 6 7 8 |
$ brew link python@2 Linking /usr/local/Cellar/python@2/2.7.15_1... 5 symlinks created #如果曾经安装过pip可能导致pip被链接到系统的python版本,可是系统目录上各种无权限,因此我们移除已经安装的pip,重新链接pip到brew安装的python $ sudo rm -rf /usr/local/bin/pip $ brew reinstall python2 |
今天刚好遇到这个问题,感谢老哥!