標籤:
由於 OS X El Capitan 採用了 System Integrity Protection 保護技術,導致 sudo pip install 安裝python包時會產生報錯:
1 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs2 makedirs(head, mode)3 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs4 mkdir(name, mode)5 OSError: [Errno 1] Operation not permitted: ‘/System/Library/Frameworks/Python.framework/Versions/2.7/selenium‘
SIP 相關命令 csrutil:
1 xx:~ $ csrutil 2 usage: csrutil <command> 3 Modify the System Integrity Protection configuration. All configuration changes apply to the entire machine. 4 Available commands: 5 6 clear 7 Clear the existing configuration. Only available in Recovery OS. 8 disable 9 Disable the protection on the machine. Only available in Recovery OS.10 enable11 Enable the protection on the machine. Only available in Recovery OS.12 status13 Display the current configuration.14 15 netboot16 add <address>17 Insert a new IPv4 address in the list of allowed NetBoot sources.18 list19 Print the list of allowed NetBoot sources.20 remove <address>21 Remove an IPv4 address from the list of allowed NetBoot sources.
查看當前SIP狀態:
1 xx:~ $ csrutil status2 System Integrity Protection status: enabled.
受到SIP保護的路徑:
- /System
- /usr
- /bin
- /sbin
- OS X 預裝的應用
如果需要全域安裝python包,則需要先關閉SIP,具體方法如下:
1、重啟系統,重啟過程中按住option然後選擇恢複分區
2、進入恢複系統後點擊菜單“工具 + 生產力”,開啟終端,輸入csrutil disable
3、正常重啟
4、sudo pip install xx包
5、安裝完畢後建議進入恢複分區通過終端開啟SIP: csrutil enable
另外建議:關閉SIP後安裝virtualenv,然後開啟SIP,後續通過virtualenv進行環境管理。
參考連結:
http://stackoverflow.com/questions/33004708/osx-el-capitan-sudo-pip-install-oserror-errno-1-operation-not-permitted
http://www.cnblogs.com/xiongqiangcs/p/4914049.html
https://support.apple.com/en-us/HT204899
Mac OS X El Capitan (10.11) sudo pip install 報錯 “OSError: [Errno 1] Operation not permitted”