makecython++ causes fatal error: Python.h: No such file or directory despite python3-dev installed
Asked Answered
O

1

7

My makefile:

SHELL := /bin/bash

.PHONY: all
all:
    pip install runcython
    makecython++ stitch_wrapper.pyx "" "stitch_rects.cpp ./hungarian/hungarian.cpp"

hungarian: hungarian/hungarian.so

hungarian/hungarian.so:
    cd hungarian && \
    TF_INC=$$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())') && \
    if [ `uname` == Darwin ];\
    then g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I $$TF_INC -undefined dynamic_lookup;\
    else g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I  $$TF_INC; fi

I have already installed

-cython
-runcython
-python-dev
-python3-dev
-cffi

Unfortunately I continue to get the error:

pkg-config: command not found
.cpp:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 1
Orthodoxy answered 27/3, 2017 at 1:34 Comment(5)
See https://mcmap.net/q/20731/-fatal-error-python-h-no-such-file-or-directory. You need to specify the path in the make file. I believe Python.h is not automatically on the include path to help multiple versions not conflictClow
@Dawon I have added flag -I/usr/include/python3.5 -lpython3.5 after makecython++command line with no success and get the error makecython++ requires a *.pyx file. seems that flag syntax isn't correct for makecython++Orthodoxy
I'm not really familiar with makecython++ so I'm guessing a bit, but I think you want to send those flags to g++ rather than makecython++Clow
@Clow in my case I have to use makecython++ not gcc. How I should add \-I/usr/include/python3.5\ to path?Orthodoxy
Sorry - don't know. Looking at the source github.com/Russell91/runcython/blob/master/makecython%2B%2B it looks like it tries to do this (the pkg-config part) but I wonder if it does it for Python2 rather than Python3. I have no really idea how to fix it though.Clow
R
10

If you already have

sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libpython3-dev
sudo apt-get install libpython3.4-dev
sudo apt-get install libpython3.5-dev

the problem may be related to missing of one of these packages:

sudo apt-get install Cython
sudo apt-get install pkgconf
sudo apt-get install libpkgconf
sudo apt-get install python-pkgconfig
sudo apt-get install python3-pkgconfig
Rembrandt answered 30/3, 2017 at 0:54 Comment(1)
apt-get install libpython3.7-dev - solved "Python.h: No such file or directory" with python 3.7Chondrule

© 2022 - 2024 — McMap. All rights reserved.