2

When trying to compile pycaffe on Ubuntu 16.04, with Anaconda 3.6 installed I get the following error:

python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or directory

I have tried to install the python-devel packages with

sudo apt-get install python3-dev 
sudo apt-get install python3.5-dev
sudo apt-get install python3.6-dev 

But even after trying with each of those separately the same error occurs.

The correct PATH seems to be added in .bashrc

export PATH="home/jdevezas/anaconda/bin:$PATH"

And in Caffe's makefile.config I have

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.

ANACONDA_HOME := /home/jdevezas/anaconda

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

# Uncomment to use Python 3 (default is Python 2)
 PYTHON_LIBRARIES := boost_python3 python3.5m
 PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

I have also tried with Python 2.7 with no results. I have checked the /usr/include/python3.5m and Python.h is there. Suggestions?

karel
  • 110,292
  • 102
  • 269
  • 299
J. Devez
  • 121
  • 1
  • 1
  • 2
  • Have you tried `python.h` instead ? – Soren A Feb 18 '18 at 19:59
  • I haven't but I have checked the directories where Python.h is and it is spelled with a capital P (also the error spells it with P). But I'll give it a try and come back with a reply if it works. – J. Devez Feb 18 '18 at 20:33
  • I have however tried running "python-config --cflags" and it returns: -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes Nothing related to Python 3.6... Could this be it? – J. Devez Feb 18 '18 at 20:34

3 Answers3

0

Updated (2021-01-11): Python.h header is now in $CONDA_PREFIX/include/python3.Y (where Y is minor version) in case of Linux or $CONDA_PREFIX/include in Windows.


Old answer: python.h header is in $CONDA_PREFIX/etc/include/python3.6m directory.

cosmoscalibur
  • 1,660
  • 17
  • 23
0

For tracking down the packages a file is in, use

apt-file search Python.h 

The list (for Ubuntu 20.04) shows two likely candidates for the latest python version: libpython3.8-dev and pypy3-dev. The package you need to install is libpython3.8-dev

Install apt-file with

sudo apt-get install apt-file

Then update its database:

apt-file update
ubfan1
  • 17,041
  • 4
  • 39
  • 47
0

in my case the python folder was situated in /opt/anaconda3/include/, which I found by

$ which conda
/opt/anaconda3/bin/conda

the variable $CONDA_PREFIX was empty in my case, as

$ echo $CONDA_PREFIX

printed just an empty line.