mac 下安装caffe(一)

1.brew install --build-from-source -vd boost boost-python

这一步出错:libtool: unrecognized option `-static'

编译过程中调用了"libtool" -static -o "xx.a" "xxx.o" 命令进行静态链接。

 

MERRICKMEI-MB0:/ merrickmei$ brew unlink libtool
Unlinking /usr/local/Cellar/libtool/2.4.6_1... 0 symlinks removed
MERRICKMEI-MB0:/ merrickmei$ which libtool
/usr/local/bin/libtool
MERRICKMEI-MB0:/ merrickmei$ whereis libtool
/usr/bin/libtool

MERRICKMEI-MB0:/ merrickmei$ /usr/local/bin/libtool   -static -o
libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.


 MERRICKMEI-MB0:/ merrickmei$ /usr/bin/libtool   -static -o
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: missing argument to: -o option
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]

MERRICKMEI-MB0:/ merrickmei$ ls -l /usr/local/bin/libtool
-rwxrwxrwx  1 root  admin  280480  2 23 20:20 /usr/local/bin/libtool

 

可见,/usr/local/bin/libtool不支持-static,而/usr/bin/libtool支持-static选项。

参考:https://github.com/Homebrew/legacy-homebrew/issues/28442

MERRICKMEI-MB0:/ merrickmei$  /usr/local/bin/libtool  --version
ltmain.sh (GNU libtool) 2.2.6b
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996

/usr/local/bin/libtool 是之前自己make install手动编译安装的。
而/usr/bin/libtool 是xcode自带的。

同样make uninstall libtool:
cd libtool-2.2.6b
./configure --prefix=/usr/local  
make
sudo make uninstall

虽然有错误,但是/usr/local/bin/libtool 已经不见了。which libtool,whereis libtool都只显示/usr/bin/libtool

 

再次执行brew install --build-from-source -vd boost boost-python 就发现ok了,continue...

 

2.Python接口,进入caffe/python目录

for req in $(cat requirements.txt); do pip install $req; done

 

3.make

Makefile.config中去掉CPU_ONLY := 1的注释
cp Makefile.config.example Makefile.config
make all
make test
make runtest

 make runtest出现绿色RUN OK

4.pycaffe

 MERRICKMEI-MB0:caffe merrickmei$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:10: fatal error: 'numpy/arrayobject.h' file not found
#include <numpy/arrayobject.h>

解决:将numpy/arrayobject.h所在的路径/usr/local/lib/python2.7/site-packages/numpy/core/include 添加到

Makefile.config中的PYTHON_INCLUDE

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include\
/usr/local/lib/python2.7/site-packages/numpy/core/include

再次 make clean,make pycaffe,成功编译。。

 

添加caffe到PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/Users/work/gitclone/caffe/python

merrickmei$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe as cf
python(97549,0x7fffc7e083c0) malloc: *** malloc_zone_unregister() failed for 0x7fffc7dfe000
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/work/gitclone/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/Users/work/gitclone/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: numpy.core.multiarray failed to import

 http://stackoverflow.com/questions/33859531/runtimeerror-module-compiled-against-api-version-a-but-this-version-of-numpy-is

 

>>> import numpy as n
>>> n.__path__
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy']

>>> import sys


>>> sys.path.insert(1, "/usr/local/lib/python2.7/site-packages")


>>> import numpy >>> print numpy.__path__ ['/usr/local/lib/python2.7/site-packages/numpy']

numpy解决后再import caffe 有碰到错误:

ImportError: No module named skimage.io

 

因为使用的系统的python,而不是Anaconda Python,决定还是用Anaconda Python

 

 

参考:http://www.tuicool.com/articles/FjAnqin

 

 

posted @ 2017-02-28 09:23  mlj318  阅读(1741)  评论(0编辑  收藏  举报