Caffe: make pycaffe gives following error at Ubuntu 14.04 even I installed numpy

Created on 15 Oct 2014  ·  16Comments  ·  Source: BVLC/caffe

g++ -shared -o python/caffe/_caffe.so python/caffe/_caffe.cpp \
        .build_release/lib/libcaffe.a -fPIC -DNDEBUG -O2 -I/usr/include/python2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I.build_release/src -I./src -I./include -I/usr/local/cuda/include -Wall -Wno-sign-compare -L/usr/lib -L/usr/local/lib -L/usr/lib -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lcudart -lcublas -lcurand -lpthread -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lopenblas -lboost_python -lpython2.7
In file included from python/caffe/_caffe.cpp:12:0:
python/caffe/_caffe.hpp:8:31: fatal error: numpy/arrayobject.h: No such file or directory
 #include <numpy/arrayobject.h>
                               ^
compilation terminated.

this is the error raised as I type make pycaffe. I installed numpy by setup.py.

Most helpful comment

You may need to first relocate the file numpy/arrayobject.h on your computer using "find / -name numpy/arrayobject.h", and then modify the PYTHON_INCLUDE in the Makefile.configure.

Perhaps it's in /usr/local/lib/python2.7 instead of /usr/lib/python2.7

All 16 comments

could you run

ls /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/

this is where the arrayobject.h file should be

could you reinstall numpy?I think that may work.

You may need to first relocate the file numpy/arrayobject.h on your computer using "find / -name numpy/arrayobject.h", and then modify the PYTHON_INCLUDE in the Makefile.configure.

Perhaps it's in /usr/local/lib/python2.7 instead of /usr/lib/python2.7

after re-install it is resolved . Thanks

Replicated for Fedora 20. Had the same problem, it appears to be that numpy was in the path /usr/lib64/python2.7/site-packages/numpy so you should change your Makefile.config's Python include path to this. It happens when you install numpy through pip on a x64_86 computer. At least that's the deal for Fedora.

Had the same issue (xubuntu 14.04). I noticed that I had installed numpy with pip install --user and it was in $HOME/.local
Although I fixed by doing a sudo pip install (during reinstall), I think adding a symlink to the local folder would have worked too.

I had the same problem on Kubuntu 14.10 Plasma 4. It was also an issue around /usr/local/lib/python2.7 vs. /usr/lib/python2.7. (I had installed NumPy using sudo pip install numpy)

I did sudo apt-get install python-numpy then make clean, make pycaffe, and it seems to have done the trick... symbolic links would have been neater most likely.

(I used sudo find / -name arrayobject.h to find the right location)

In OpenSUSE 13.2, this did the trick:

sudo pip uninstall statsmodels
sudo pip uninstall numpy
sudo pip install numpy
sudo pip install statsmodels

Same on ubuntu 14.04.

sudo pip uninstall numpy
sudo pip install numpy
make clean
make pycaffe 

not helped.

I have done as Franck-Dernoncourt suggested

sudo apt-get install python-numpy then make clean, make pycaffe

and it solved problem..

I was facing the same problem on OS X El Capitan.

Maybe this is too dumb, but here is what was preventing pycaffe installation from going through:

Although the arrayobject.h file is located in,
/usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/

In Makefile, you need to change part of PYTHON_INCLUDE to
/usr/local/lib/python2.7/site-packages/numpy/core/include/

WITHOUT the numpy/

@AshishBora's solution solved the problem for me on Ubuntu 14.04

I was still having this issue and the fix is simply in the formatting of the ANACONDA_HOME variable (link):

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

Really odd.

@AshishBora's solution solved the problem for me on macOS Sierra 10.12.2

mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ make
python setup.py build_ext --inplace
running build_ext
skipping 'utils/bbox.c' Cython extension (up-to-date)
building 'utils.cython_bbox' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/utils
{'gcc': ['-Wno-cpp', '-Wno-unused-function']}
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c utils/bbox.c -o build/temp.linux-x86_64-2.7/utils/bbox.o -Wno-cpp -Wno-unused-function
utils/bbox.c:346:31: fatal error: numpy/arrayobject.h: No such file or directory
 #include "numpy/arrayobject.h"
                               ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
make: *** [all] Error 1
mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ ls
build  datasets  layer_utils  Makefile  model  nets  nms  roi_data_layer  setup.py  utils
mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ vi setup.py 
mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ ls /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
ls: cannot access /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/: No such file or directory
mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ sudo pip install numpy
[sudo] password for mona: 
The directory '/home/mona/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mona/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: numpy in /usr/local/lib/python3.4/dist-packages
mona@pascal:~/computer_vision/tf-faster-rcnn/lib$ sudo -H pip install numpy
Requirement already satisfied: numpy in /usr/local/lib/python3.4/dist-packages

@mrgloom Thanks ^_^ it worked for me too. I'm with Anaconda3 on Linux Mint.

in Ubuntu 16.04, using apt install python-numpy rather than pip install numpy works.

Was this page helpful?
0 / 5 - 0 ratings