我已经花了2天的时间,尝试了我在此网站上看到的所有内容。我试图让cython在python中编译基本的helloworld脚本,但是有错误。尽管列出的路径是正确的事实,但Gcc似乎无法看到python头文件,并且我已经验证了文件是否存在(例如c:/Python27/include/pyconfig.h),我已经包含了使用的文件我的设置。
helloWorld.pyx
print 'Hello World'
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloWorld.pyx")
)
cmd线
python setup.py build_ext --inplace --compiler = mingw32
错误
编译helloworld.pyx,因为它已更改。 Cythonizing
helloworld.pyx运行build_ext构建'helloworld'扩展
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在包含的文件中
helloworld.c:8:C:/Python27/include/pyconfig.h:68:16:io.h:没有
文件或目录C:/Python27/include/pyconfig.h:296:20:stdio.h:否
这样的文件或目录
C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / limits.h:122,来自
C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / syslimits.h:7,来自
C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / limits.h:11,来自
C:/Python27/include/Python.h:19,来自helloworld.c:16:
/mingw/lib/gcc/mingw32/3.4.5/include/limits.h:122:61:limits.h:否
这样的文件或目录在helloworld.c:16包含的文件中:
C:/Python27/include/Python.h:35:5:#error“ Python.h要求
stdio.h定义为NULL。“ C:/Python27/include/Python.h:38:20:string.h:否
这样的文件或目录C:/Python27/include/Python.h:40:19:errno.h:否
这样的文件或目录C:/Python27/include/Python.h:42:20:stdlib.h:
没有这样的文件或目录C:/Python27/include/Python.h:56:20:
assert.h:无此类文件或目录
C:/Python27/include/Python.h:58,来自helloworld.c:16:
C:/Python27/include/pyport.h:325:76:math.h:没有这样的文件或目录
C:/Python27/include/pyport.h:338:18:time.h:没有这样的文件或目录
C:/Python27/include/pyport.h:390:22:sys / stat.h:没有这样的文件或
目录在C:/Python27/include/Python.h:80中包含的文件中
helloworld.c:16:C:/Python27/include/object.h:307:错误:语法错误
在“文件” C:/Python27/include/object.h:459之前:错误:语法错误
在“ FILE”之前在C:/Python27/include/Python.h:85包含的文件中,
来自helloworld.c:16:C:/Python27/include/unicodeobject.h:57:19:
ctype.h:没有这样的文件或目录
C:/Python27/include/unicodeobject.h:120:21:wchar.h:没有这样的文件或
目录在C:/Python27/include/Python.h:108包含的文件中
helloworld.c:16:C:/Python27/include/fileobject.h:12:错误:语法
“ FILE”之前的错误C:/Python27/include/fileobject.h:12:警告:否
结构或联合结尾处的分号
C:/Python27/include/fileobject.h:15:错误:语法错误位于“
令牌C:/Python27/include/fileobject.h:33:错误:语法错误
'}'令牌C:/Python27/include/fileobject.h:33:警告:键入默认值
到
int' in declaration of
PyFileObject'C:/Python27/include/fileobject.h:33:警告:数据定义没有
类型或存储类C:/Python27/include/fileobject.h:44:错误:
''标记C:/Python27/include/fileobject.h:45之前的语法错误:
错误:“”标记之前的语法错误
C:/Python27/include/fileobject.h:46:错误:语法错误位于“
令牌C:/Python27/include/fileobject.h:46:警告:类型默认为
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 to
__ PYX_NAN'声明中的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
int':helloworld.c:315:警告:函数
memset' helloworld.c: In function
__ Pyx_PyUnicode_FromString'的隐式声明:helloworld.c:1423:警告:隐式函数
strlen' helloworld.c: In function
__ Pyx_PyObject_AsStringAndSize'的声明:helloworld.c:1474:警告:隐式函数“ assert”的声明错误:命令
'C:\ MinGW \ bin \ gcc.exe'失败,退出状态为1
最佳答案
正如IanH所评论的那样,看来GCC无法找到Python标头中包含的标准C标头,而不是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/