Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caffe+GPU+Opencv3.1+Python3.5+Anaconda:fatal error: Python.h: No such file or directory

Briefly I want to use Caffe these day for my project. My OS is Ubuntu 14.04, with Opencv3.1+Python3.5+Anaconda+GPU I have already passed all:

make all
make pycaffe
make test
make runtest

However when can try to make pycaffe, it cannot pass:

Python.h: No such file or directory

Here is my 'makefile.config', and I am sure the 'Python.h' has already in the path, which make me quite confused.

USE_CUDNN := 1
OPENCV_VERSION := 3
ANACONDA_HOME := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
         $(ANACONDA_HOME)/include/python3.5m \
         $(ANACONDA_HOME)/lib/python3.5/site-packages/numpy/core/include \
PYTHON_LIB := $(ANACONDA_HOME)/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
USE_PKG_CONFIG := 1
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

Because I use Python3.5, so I uncomment the following:

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

I really appreciate someone could help,

like image 209
Kaku Avatar asked Feb 07 '23 00:02

Kaku


2 Answers

You have two definitions for PYTHON_INCLUDE: you need to decide if you go for the "python3" flavor, or the "anaconda" flavor...

Where is your python.h file anyway? try in shell

find / -name "Python.h" -type f

and see where it actually is. Then pick the correct settings for PYTHON_INCLUDE in your makefile.config

like image 192
Shai Avatar answered Feb 08 '23 12:02

Shai


I almost spent(waisted) one week to configure caffe on Ubuntu 14.04, the reason why it too time consuming is that I am using the newest version of Opencv Python and anaconda. Here I want to share my experience.

  1. Makefile.config

    # cuDNN acceleration switch (uncomment to build with cuDNN).
    USE_CUDNN := 1
    # Uncomment if you’re using OpenCV 3
    OPENCV_VERSION := 3
    # CUDA directory contains bin/ and lib/ directories that we need.
    CUDA_DIR := /usr/local/cuda
    # CUDA architecture setting: going with all of them.
    # For CUDA < 6.0, comment the *_50 lines for compatibility.
    CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
    -gencode arch=compute_20,code=sm_21 \
    -gencode arch=compute_30,code=sm_30 \
    -gencode arch=compute_35,code=sm_35 \
    -gencode arch=compute_50,code=sm_50 \
    -gencode arch=compute_50,code=compute_50
    # BLAS choice: atlas for ATLAS (default)
    BLAS := atlas
    # We need to be able to find Python.h and numpy/arrayobject.h.
    ANACONDA_HOME := $(HOME)/anaconda3
    PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
    $(ANACONDA_HOME)/include/python3.5m \
    $(ANACONDA_HOME)/lib/python3.5/site-packages/numpy/core/include \
    # Uncomment to use Python 3 (default is Python 2)
    PYTHON_LIBRARIES := boost_python3 python3.5m
    # We need to be able to find libpythonX.X.so or .dylib.
    PYTHON_LIB := $(ANACONDA_HOME)/lib
    # Whatever else you find you need goes here.
    INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
    # N.B. both build and distribute dirs are cleared on `make clean`
    BUILD_DIR := build
    DISTRIBUTE_DIR := distribute
    # The ID of the GPU that ‘make runtest’ will use to run unit tests.
    TEST_GPUID := 0
    # enable pretty build (comment to see full commands)
    Q ?= @
    
  2. /.bashrc

    #Caffemake
    export PYTHONPATH=~/caffe/python/:$PYTHONPATH
    #Opencv
    export LD_LIBRARY_PATH=/home/kaku/anaconda3/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=”/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH”
    
  3. Notes:

    1. library must be installed:
    libboost-all-dev, although in some tutorial mentioned must install libboost1.55-all-dev.
    protobuf-cpp-3.0.0-beta-2.zip or upper one
    protobuf-python-3.0.0-beta-2.zip or upper one
    http://blog.csdn.net/lien0906/article/details/51784191
    https://github.com/google/protobuf/issues/1276
    
  4. Other Debug: Details in my own blog.

like image 25
Kaku Avatar answered Feb 08 '23 13:02

Kaku