mac 下安装caffe(二)

使用Anaconda Python

1.brew edit opencv

      args << "-DPYTHON_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
      args << "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"

替换成
      args << "-DPYTHON_LIBRARY=/Users/work/anaconda/lib/libpython2.7.#{dylib}"
      args << "-DPYTHON_INCLUDE_DIR=/Users/work/anaconda/include/python2.7"

2.去掉ANACONDA_HOME的注释并修改为安装的路径

 ANACONDA_HOME := /Users/work/anaconda
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include 
         $(ANACONDA_HOME)/include/python2.7 
         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

3.再次make

出错:Warning! ***HDF5 library version mismatched error***

brew uninstall hdf5

出错:

ld: library not found for -lhdf5_hl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [.build_release/lib/libcaffe.so.1.0.0-rc5] Error 1

 

makefile中还需要修改PYTHON_LIB如下:

#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

出错:make runtest

.build_release/tools/caffe

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib

  Referenced from: /Users/work/gitclone/caffe/.build_release/tools/caffe

  Reason: image not found

make: *** [runtest] Abort trap: 6

 

设置一下环境变量DYLD_FALLBACK_LIBRARY_PATH 

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Users/work/anaconda/lib:/usr/local/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH

依然出错。。。

哎哎哎,,,参照 http://playittodeath.ru/how-to-install-caffe-on-mac-os-x-yosemite-10-10-4/ 重新卸载编译吧,依然是这个错误

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Users/work/anaconda/lib:/usr/local/lib:/usr/lib

export CPLUS_INCLUDE_PATH=/Users/work/anaconda/include/python2.7/: 

正确的方法为将添加libhdf5_hl.10.dylib所在路径添加到rpath

install_name_tool -add_rpath '/Users/work/anaconda/lib'  /Users/work/gitclone/caffe/.build_release/tools/caffe

test_all.testbin 继续出错-->

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib

  Referenced from: /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

  Reason: image not found

make: *** [runtest] Abort trap: 6

再次添加rpath

install_name_tool -add_rpath '/Users/work/anaconda/lib'  /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

#这句不用 install_name_tool -add_rpath '/Users/work/anaconda/lib' /Users/work/gitclone/caffe/.build_release/lib/libcaffe.so

 

终于make runtest成功

Library not loaded错误参考:https://github.com/BVLC/caffe/issues/2320 

install_name_tool 参考 http://www.jianshu.com/p/193ba07dadcf 

查看可执行文件的依赖情况: otool -L  /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

 

4.make pycaffe 

 import caffe 出错:

ImportError: No module named google.protobuf.internal

 

conda install protobuf 即可解决

 

5.其他错误

a. RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9

系统自带python的numpy版本为1.8.0rc1旧版本

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

 

使用pip install numpy --upgrade 升级到1.12.0版本即可

 

 

 

原文地址:https://www.cnblogs.com/mlj318/p/6478247.html