Cython Fatal Error: Python.h No such file or directory

Cython Fatal Error: Python.h No such file or directory

我一直在使用 Cython 将我的 Python 文件编译成 C 文件,然后使用 MinGW 从 C 文件创建可执行文件。 Cython 工作正常,我可以在命令行中输入 cython test.pyx 并获得一个 C 文件。问题是当我试图从 C 文件编译可执行文件时。如果我输入 gcc test.c 我会收到以下错误:

test.c:4:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.

非常感谢您的帮助。我是 运行 windows 7 和 python 3.5.

您可能没有安装 python-dev。根据您的 OS,您需要执行以下操作:

sudo apt-get install python-dev

你会在 Ubuntu

做什么

在 gcc 中

#include "file.h"

告诉 gcc 在 test.c 所在的同一目录中查找文件,并且

#include <file.h>

表示在gcc的include路径中找到file.h,可以加上-I

gcc -I/path/to/the/file_h test.c

你可以试试

#include <Python.h>

另见fatal error: Python.h: No such file or directory