Cython 致命错误:Python.h 没有这样的文件或目录

问题描述 投票:0回答:3

我一直在使用 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 c gcc cython
3个回答
37
投票

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

sudo apt-get install python-dev

这就是你在 Ubuntu 上要做的事情


5
投票

在海湾合作委员会

#include "file.h"

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

#include <file.h>

表示在gcc包含路径中查找file.h,可以用-I添加

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

你可以尝试一下

#include <Python.h>

另请参阅致命错误:Python.h:没有这样的文件或目录


0
投票

需要安装构建等开发工具所需的Python版本:

# python 3.12
sudo apt-get install python3.12-dev
© www.soinside.com 2019 - 2024. All rights reserved.