因爲 OS X El Capitan 採用了 System Integrity Protection 保護技術,致使 sudo pip install 安裝python包時會產生報錯:html
1 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs 2 makedirs(head, mode) 3 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs 4 mkdir(name, mode) 5 OSError: [Errno 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/selenium'
SIP 相關命令 csrutil:python
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 enable 11 Enable the protection on the machine. Only available in Recovery OS. 12 status 13 Display the current configuration. 14 15 netboot 16 add <address> 17 Insert a new IPv4 address in the list of allowed NetBoot sources. 18 list 19 Print the list of allowed NetBoot sources. 20 remove <address> 21 Remove an IPv4 address from the list of allowed NetBoot sources.
查看當前SIP狀態:api
1 xx:~ $ csrutil status 2 System Integrity Protection status: enabled.
受到SIP保護的路徑:app
若是須要全局安裝python包,則須要先關閉SIP,具體方法以下:python2.7
一、重啓系統,重啓過程當中按住option而後選擇恢復分區工具
二、進入恢復系統後點擊菜單「實用工具」,打開終端,輸入csrutil disablespa
三、正常重啓code
四、sudo pip install xx包htm
五、安裝完畢後建議進入恢復分區經過終端打開SIP: csrutil enableblog
另外建議:關閉SIP後安裝virtualenv,而後打開SIP,後續經過virtualenv進行環境管理。
參考連接: