python - 尝试使用 cython 和 mingw 编译 hello world 时出错

标签 python gcc mingw cython

我已经花了 2 天时间尝试了我在这个网站上看到的所有其他内容。我试图让 cython 在 python 中编译基本的 helloworld 脚本,但有错误。尽管列出的路径是正确的并且我已经验证文件在那里(例如 c:/Python27/include/pyconfig.h)我已经包含了使用的文件,但 Gcc 似乎无法看到 python 头文件我的设置。

Hello World .pyx

print 'Hello World'

设置.py
from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloWorld.pyx")
)

命令行

python setup.py build_ext --inplace --compiler=mingw32

错误

Compiling helloworld.pyx because it changed. Cythonizing helloworld.pyx running build_ext building 'helloworld' extension C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python27\include -IC:\Pytho n27\PC -c helloworld.c -o build\temp.win32-2.7\Release\helloworld.o In file included from helloworld.c:8: C:/Python27/include/pyconfig.h:68:16: io.h: No such file or directory C:/Python27/include/pyconfig.h:296:20: stdio.h: No such file or directory In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/include/limits.h:122 , from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/include/syslimits.h: 7, from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/include/limits.h:11, from C:/Python27/include/Python.h:19, from helloworld.c:16: /mingw/lib/gcc/mingw32/3.4.5/include/limits.h:122:61: limits.h: No such file or directory In file included from helloworld.c:16: C:/Python27/include/Python.h:35:5: #error "Python.h requires that stdio.h define NULL." C:/Python27/include/Python.h:38:20: string.h: No such file or directory C:/Python27/include/Python.h:40:19: errno.h: No such file or directory C:/Python27/include/Python.h:42:20: stdlib.h: No such file or directory C:/Python27/include/Python.h:56:20: assert.h: No such file or directory In file included from C:/Python27/include/Python.h:58, from helloworld.c:16: C:/Python27/include/pyport.h:325:76: math.h: No such file or directory C:/Python27/include/pyport.h:338:18: time.h: No such file or directory C:/Python27/include/pyport.h:390:22: sys/stat.h: No such file or directory In file included from C:/Python27/include/Python.h:80, from helloworld.c:16: C:/Python27/include/object.h:307: error: syntax error before "FILE" C:/Python27/include/object.h:459: error: syntax error before "FILE" In file included from C:/Python27/include/Python.h:85, from helloworld.c:16: C:/Python27/include/unicodeobject.h:57:19: ctype.h: No such file or directory C:/Python27/include/unicodeobject.h:120:21: wchar.h: No such file or directory In file included from C:/Python27/include/Python.h:108, from helloworld.c:16: C:/Python27/include/fileobject.h:12: error: syntax error before "FILE" C:/Python27/include/fileobject.h:12: warning: no semicolon at end of struct or union C:/Python27/include/fileobject.h:15: error: syntax error before '' token C:/Python27/include/fileobject.h:33: error: syntax error before '}' token C:/Python27/include/fileobject.h:33: warning: type defaults to int' in declaration ofPyFileObject' C:/Python27/include/fileobject.h:33: warning: data definition has no type or storage class C:/Python27/include/fileobject.h:44: error: syntax error before '' token C:/Python27/include/fileobject.h:45: error: syntax error before '' token C:/Python27/include/fileobject.h:46: error: syntax error before '' token C:/Python27/include/fileobject.h:46: warning: type defaults to int' in declaration of PyFile_AsFile' C:/Python27/include/fileobject.h:46: warning: data definition has no type or storage class C:/Python27/include/fileobject.h:47: error: syntax error before '*' token C:/Python27/include/fileobject.h:48: error: syntax error before '*' token C:/Python27/include/fileobject.h:65: error: syntax error before "FILE" C:/Python27/include/fileobject.h:66: error: syntax error before "FILE" In file included from C:/Python27/include/Python.h:127, from helloworld.c:16: C:/Python27/include/pythonrun.h:35: error: syntax error before '*' token C:/Python27/include/pythonrun.h:36: error: syntax error before '*' token C:/Python27/include/pythonrun.h:38: error: syntax error before '*' token C:/Python27/include/pythonrun.h:39: error: syntax error before '*' token C:/Python27/include/pythonrun.h:40: error: syntax error before '*' token C:/Python27/include/pythonrun.h:45: error: syntax error before '*' token C:/Python27/include/pythonrun.h:55: error: syntax error before '*' token C:/Python27/include/pythonrun.h:61: error: syntax error before '*' token C:/Python27/include/pythonrun.h:78: error: syntax error before '*' token C:/Python27/include/pythonrun.h:152: error: syntax error before '*' token C:/Python27/include/pythonrun.h:154: error: syntax error before '*' token In file included from C:/Python27/include/Python.h:129, from helloworld.c:16: C:/Python27/include/sysmodule.h:12: error: syntax error before '*' token C:/Python27/include/sysmodule.h:12: error: syntax error before "FILE" C:/Python27/include/sysmodule.h:12: warning: type defaults toint' in declaration of PySys_GetFile' C:/Python27/include/sysmodule.h:12: warning: data definition has no type or storage class In file included from C:/Python27/include/Python.h:131, from helloworld.c:16: C:/Python27/include/import.h:39: error: syntax error before "FILE" helloworld.c: In function__PYX_NAN': helloworld.c:315: warning: implicit declaration of function memset' helloworld.c: In function __Pyx_PyUnicode_FromString': helloworld.c:1423: warning: implicit declaration of function strlen' helloworld.c: In function __Pyx_PyObject_AsStringAndSize': helloworld.c:1474: warning: implicit declaration of function `assert' error: command 'C:\MinGW\bin\gcc.exe' failed with exit status 1

最佳答案

正如 IanH 评论的那样,GCC 似乎无法找到 Python header 中包含的标准 C header ,而不是 Cython 的问题。你能编译一个简单的 C 程序吗,如下所示:

#include <stdio.h>
int main(void)
{
  printf("Hello World\n");
  return 0;
}

编译:

$ gcc hello.c -o hello.exe

关于python - 尝试使用 cython 和 mingw 编译 hello world 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26182725/

相关文章:

python - 按顺序打印字典键和值

c - 如何从 C 代码生成#define 值列表?

c++ - C/C++ 中有符号整数表达式的代数归约

c++ - 是否可以查看在命令行应用程序运行后执行了哪些行?

c++ - 编译器似乎拒绝成员之前的类标识符初始化

c++ - MinGW C++ : Reading a file with non-ascii file name

python - 修改 numpy 数组中的值

python - 将两本词典合二为一

python - 在 Google App Engine 中安装常用库

c++ - Itanium 和 MSVC ABI 中跨模块边界的 RTTI