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

2024-04-25 11:39:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用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.

我真的很感谢你的帮助。我正在运行Windows7和Python3.5。


Tags: 文件no命令行test可执行文件键入错误error
2条回答

在合同通用条款中

#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

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

sudo apt-get install python-dev

这就是你在Ubuntu上要做的

相关问题 更多 >