Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make pycaffe fatal error: 'Python.h' file not found

I compiled caffe on a mac running OSX 10.9.5 and I know trying to compile pycaffe. When I run make pycaffe in the caffe root folder, I get:

CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:1:10: fatal error: 'Python.h' file not found
#include <Python.h>  // NOLINT(build/include_alpha)
         ^
1 error generated.
make: *** [python/caffe/_caffe.so] Error 1

how can I fix this?

Perhaps is something wrong with Makefile.config. How do I know what is my PYTHONPATH?

like image 514
Andrea Avatar asked Jul 11 '15 14:07

Andrea


People also ask

How do I fix Python H No such file or directory?

You encounter "Python. h: No such file or directory" error while trying to build a shared library using the file extension of another language ( e.g. 'C' ). If you are trying to build a shared library using the file extension of another language, you need to install the correct development version of Python.

Where is Python h file located?

The header files are typically installed with Python. On Unix, these are located in the directories prefix/include/pythonversion/ and exec_prefix/include/pythonversion/ , where prefix and exec_prefix are defined by the corresponding parameters to Python's configure script and version is '%d.


2 Answers

Looking at the comments, I see that you use Anaconda. In Makefile.config, you should uncomment the lines dedicated to Anaconda:

# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
        # $(ANACONDA_HOME)/include/python2.7 \
        # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

Python.h is in $(ANACONDA_HOME)/include/python2.7 as you can see running sudo find / -name 'Python.h'.

like image 195
Franck Dernoncourt Avatar answered Nov 15 '22 15:11

Franck Dernoncourt


I met this problem too. I have set the PYTHON_INCLUDE PATH

    PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
    $(ANACONDA_HOME)/include/python2.7

But it still can't find the Python.h

So I just give the include path manually to the compiler as follows:

    export CPLUS_INCLUDE_PATH=/home/woolawren/anaconda2/include/python2.7/:$CPLUS_INCLUDE_PATH

if you don't use anaconda2, you can use:

    export CPLUS_INCLUDE_PATH=/usr/include/python2.7:$CPLUS_INCLUDE_PATH

I have successfully done "make pycaffe" by doing this.

like image 41
WooLaw Ren Avatar answered Nov 15 '22 16:11

WooLaw Ren