makecython++导致致命错误:Python.h:没有这个文件或目录,尽管已安装python3-dev。

7

我的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

我已经安装好了。
-cython
-runcython
-python-dev
-python3-dev
-cffi

很遗憾,我仍然收到错误提示:
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

请参见https://dev59.com/ZmEi5IYBdhLWcg3wMZ3a#21530866。您需要在makefile中指定路径。我相信Python.h不会自动添加到包含路径中,以避免多个版本冲突。 - DavidW
@Dawon 我在makecython++命令行后添加了标志-I/usr/include/python3.5 -lpython3.5,但是没有成功,并且出现了错误makecython++需要一个*.pyx文件。 看起来这个标志的语法对于makecython++不正确。 - AndreaF
我对 makecython++ 不是很熟悉,所以只能猜测一下,但我认为你想将这些标志发送给 g++ 而不是 makecython++ - DavidW
@DavidW 在我的情况下,我必须使用makecython++而不是gcc。我应该如何将-I/usr/include/python3.5\添加到路径中? - AndreaF
抱歉 - 不知道。从源代码 https://github.com/Russell91/runcython/blob/master/makecython%2B%2B 来看,它似乎尝试这样做(pkg-config 部分),但我想知道它是否适用于 Python2 而不是 Python3。然而,我真的不知道如何修复它。 - DavidW
1个回答

10
如果您已经有
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

问题可能与缺少以下其中一个软件包有关:

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

1
apt-get install libpython3.7-dev - 使用python 3.7解决了"Python.h: No such file or directory"的问题 - resident

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接