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

z9zf31ra  于 2024-01-06  发布在  Python
关注(0)|答案(4)|浏览(137)

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

os8fio9y

os8fio9y1#

你可能还没有安装python-dev。根据你的操作系统,你需要这样做:

sudo apt-get install python-dev

字符串
这就是你在Ubuntu上所做的

plicqrtu

plicqrtu2#

海湾合作委员会

#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>


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

pwuypxnk

pwuypxnk3#

它需要安装development tools for building, etc.以获得所需的Python版本:

# python 3.12
sudo apt install python3.12-dev

字符串

qmb5sa22

qmb5sa224#

在makefile中将-I/path/to/the/file_h添加到gcc后,它可以工作:

gcc -I/path/to/the/file_h

字符串

相关问题