解決 Mac OS X 10.11 安裝 sip 沒有權限的問題

在搭建 PYQT 的過程中我遇上了一個非常噁心的問題,在安裝 sip 的時候編譯源碼之後的安裝過程中一直提示我:Operation not permitted ,我甚至重裝了系統也無濟於事,最終通過查資料解決了問題。

安裝 sip

下載 sip 源碼包解壓之後進入它的目錄下:

python configure.py
sudo make
sudo make install

這時出現了一個很噁心的報錯提示:

cp -f sip /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip
cp: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip: Operation not permitted
make[1]: *** [install] Error 1
make: *** [install] Error 2

於是乎,我用 su 登錄 Shell,在重複以上過程,無果。

之後,我又使用 brew install sip,報同樣的錯誤。

然後我又進入 /System/Library/Frameworks/Python.framework 目錄打算一探究竟:

此處輸入圖片的描述

試圖修改它的權限,結果:

此處輸入圖片的描述

原因

經歷了XCode編譯器代碼被注入的事件後,這次 Mac OS X El Capitan系統的升級,啓用了更高的安全性保護機制:系統完整性保護System Integrity Protection (SIP)。簡單來講就是更加強制性的保護系統相關的文件夾。開發者不能直接操作相關的文件內容。

蘋果官方給出的解釋:

System Integrity Protection is a security technology in OS X El Capitan that’s designed to help prevent potentially malicious software from modifying protected files and folders on your Mac.
In OS X, the “root” user account previously had no permission restrictions and could access any system folder or application on your Mac. Software gained root-level access when you entered your administrator name and password to install it and could then modify or overwrite any system file or application.
System Integrity Protection restricts the root account and limits the actions that the root user can perform on protected parts of OS X.
Paths and applications protected by System Integrity Protection include:
/System
/usr
/bin
/sbin
Apps that are pre-installed with OS X
Paths and applications that third-party apps and installers can write to include:
/Applications
/Library
/usr/local
System Integrity Protection is designed to allow modifications of these protected parts only by processes that are signed by Apple and have special entitlements to write to system files, like Apple software updates and Apple installers.
Apps that you download from the Mac App Store already work with System Integrity Protection. Other third-party software that conflicts with System Integrity Protection might be set aside when you upgrade to OS X El Capitan.
System Integrity Protection also helps prevent software from changing your startup volume. To boot your Mac from a different volume, you can use the Startup Disk pane in System Preferences or you can hold down the Option key while you reboot, and select a volume from the list.
Information about products not manufactured by Apple, or independent websites not controlled or tested by Apple, is provided without recommendation or endorsement. Apple assumes no responsibility with regard to the selection, performance, or use of third-party websites or products. Apple makes no representations regarding third-party website accuracy or reliability. Risks are inherent in the use of the Internet. Contact the vendor for additional information. Other company and product names may be trademarks of their respective owners.
https://support.apple.com/en-us/HT204899

解決方案

其實解決方案就已經很簡單了,既然是系統中有 SIP 的問題,那麼我們把它關閉就好了:

  1. 重啓系統
  2. 按住 Command + R 進入 Recoverary 模式
  3. 點擊 實用工具 > 終端
  4. 輸入 csrutil disable
  5. 重啓系統

這時我們再重新編譯安裝 sip 就沒有任何問題了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章