9

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?

Andrea
  • 302
  • 2
  • 6
  • 12
  • Look in the include folder of your Python installation. – Malik Brahimi Jul 11 '15 at 15:07
  • Hi @MalikBrahimi, could you be more specific please? – Andrea Jul 11 '15 at 15:07
  • if i do `cd /usr/local/bin/python' it tells me "not a directory. If I go to /usr/local/bin/ within finder, I see a python icon, but no folder. – Andrea Jul 11 '15 at 15:21
  • Look in the folders mentioned [here](http://stackoverflow.com/questions/6819661/python-location-on-mac-osx). – Malik Brahimi Jul 11 '15 at 15:22
  • Ok! using which Python i get /Users/Andrea/anaconda/bin/Python. – Andrea Jul 11 '15 at 15:27
  • What do I do now @MalikBrahimi? Do i need to change this line "PYTHON_INCLUDE := /usr/local/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include" in Makefile.config? – Andrea Jul 11 '15 at 15:28
  • Inside the include folder there should be a `Python.h` which you can copy into your C++ project. – Malik Brahimi Jul 11 '15 at 15:30
  • @MalikBrahimi I dont have a C++ project. this question is specifically about installing compiling pycaffe – Andrea Jul 11 '15 at 15:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83036/discussion-between-andrea-di-biagio-and-malik-brahimi). – Andrea Jul 11 '15 at 15:33

4 Answers4

9

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'.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
  • I've just realized that I only partially uncommented those anaconda-related PYTHON_INCLUDE lines... Ouch, had to re-make. Thanks a lot for pointing out the details! – alisa Nov 08 '16 at 17:45
3

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
WooLaw Ren
  • 31
  • 2
0

I just finished a tedious Caffe install on Arch Linux; hopefully my install notes (link below) will help others.

While specific to my Caffe install, those notes address the "Python.h" install error (this Question), as well as a downstream issue mentioned in another SO question,

Import caffe error.

https://stackoverflow.com/questions/28177298/import-caffe-error

My gist file (notes):

Caffe Installation Notes

https://gist.github.com/victoriastuart/fb2cb22209ccb2771963a25c06221213
Community
  • 1
  • 1
Victoria Stuart
  • 4,610
  • 2
  • 44
  • 37
0

I uncommented the below code in Makefile.config

PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

Then did sudo make pycaffe.

It worked.