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 directoryI 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/includeI have also tried with Python 2.7 with no results. I have checked the /usr/include/python3.5m and Python.h is there. Suggestions?
33 Answers
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-fileThen update its database:
apt-file update in my case the python folder was situated in /opt/anaconda3/include/, which I found by
$ which conda
/opt/anaconda3/bin/condathe variable $CONDA_PREFIX was empty in my case, as
$ echo $CONDA_PREFIXprinted just an empty line.
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.