我一直在使用 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。根据您的操作系统,您需要执行以下操作:
sudo apt-get install python-dev
这就是你在 Ubuntu 上要做的事情
在海湾合作委员会
#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版本:
# python 3.12
sudo apt-get install python3.12-dev