python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
原创
©著作权归作者所有:来自51CTO博客作者是念的原创作品,请联系作者获取转载授权,否则将追究法律责任
我在编译pycaffe的操作的时候,看见了下面的错误,编译命令为:
错误的输出为:
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:507: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1
通过查阅资料,我的解决办法是:
sudo gedit Makefile.config
#找到这条语句,然后要加一个local:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
然后运行命令:
输出为:
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
然后加入环境变量,我的caffe路径为export PYTHONPATH=/home/whsyxt/Downloads/caffe/python:$PYTHONPATH:
sudo gedit ~/.bashrc #打开
export PYTHONPATH=/home/usrname/caffe/python:$PYTHONPATH #配置文件最后写入该路径,
source ~/.bashrc #生效
然后运行python,测试一下:
whsyxt@whsyxt:~/Downloads/caffe/python$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> exit()
成功了。