1.在安裝Dlib庫之前需要安裝的庫:opencv,numpy

2.安裝Xquartz2.7.11

Xquartz是執行Unix程式的圖形視窗環境,為了相容Unix和Linux下移植過來的程式就需要安裝,dlib需要X11,但mac沒有自帶,所以直接上網址下載安裝就好了

地址:https://www.xquartz.org/

預設安裝目錄為/opt/X11,需要在/usr/local/X11下面建立軟連結,需要重啟

cd /usr/local/opt
ln -s /opt/X11 X11

3.安裝Dlib

網上這麼多種方法,踩了這麼多坑,最後還是直接在Git上面下載成功了

git clone https://github.com/davisking/dlib.git

下載後解壓安裝Dlib

cd dlib/examples
mkdir build
cd build
cmake ..
cmake --build . --config Release

安裝python模組

cd dlib
sudo python setup.py install
python
import dlib
#如果沒有錯就對啦

在執行 sudo python setup.py install 的時候 ,可能出現錯誤

Could NOT find Boost

這個時候說明boost沒有安裝好,安裝檔案給出瞭解決辦法

*****************************************************************
-- To compile Boost.Python yourself download boost from boost.org and then go into the boost root folder
-- and run these commands:
-- ./bootstrap.sh --with-libraries=python
-- ./b2
-- sudo ./b2 install *****************************************************************

先去下載好boost,然後在boost所在的資料夾執行命令

這個時候再執行 import dlib 不會報錯

但是執行的時候可能會報錯

Library not loaded: libboost_python.dylib

這是因為升級了OSX,蘋果的System Integrity Protection (SIP),不管你是不是在根使用者下,一些軟體程式都無法正常執行,這個時候進入蘋果恢復模式(開機黑屏時按command+R)

然後輸入命令

csrutil disable

現在就可以了

參考文件:

http://www.macworld.com/article/2986118/security/how-to-modify-system-integrity-protection-in-el-capitan.html

http://blog.csdn.net/quincuntial/article/details/53572415