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

Mar*_*ton 6 c python gcc cython

我一直在使用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.
Run Code Online (Sandbox Code Playgroud)

我真的很感激一些帮助.我正在运行Windows 7和python 3.5.

bru*_*ceg 13

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

sudo apt-get install python-dev
Run Code Online (Sandbox Code Playgroud)

这是你在Ubuntu上做的

  • btw:对于python3用户,你需要使用`sudo apt-get install python3-dev` (3认同)
  • 附加评论:对于特殊的 python 版本,例如 3.11,可以附加版本号 `sudo apt-get install python3.11-dev` (3认同)
  • @The Bndr 都没有为我工作,我正在 ubuntu 18.04 上工作。已经安装了两个开发环境。使用 pycharm 一切都是最新版本。 (2认同)

小智 5

在gcc

#include "file.h"
Run Code Online (Sandbox Code Playgroud)

告诉gcc在test.c所在的同一目录中找到该文件

#include <file.h>
Run Code Online (Sandbox Code Playgroud)

意味着在gcc包含路径中查找file.h,可以使用-I添加

gcc -I/path/to/the/file_h test.c
Run Code Online (Sandbox Code Playgroud)

你可能会试试

#include <Python.h>
Run Code Online (Sandbox Code Playgroud)

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