Cython Wiki的Hello World [英] Hello World from cython wiki not working

查看:93
本文介绍了Cython Wiki的Hello World的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Cython那里学习本教程: http://docs.cython.org/docs/tutorial.html#the-basics-of-cython ,我遇到了问题。



文件非常简单。我有一个helloworld.pyx:

  print Hello World 

和setup.py:

 从distutils.core导入从distutils.extension import设置
从Cython.Distutils导入扩展
build_ext

setup(
cmdclass = {'build_ext':build_ext},
ext_modules = [Extension( helloworld,[ helloworld.pyx])]

然后使用标准命令进行编译:

  python setup.py build_ext --inplace 

我遇到以下错误:

 运行build 
运行build_ext
构建'helloworld'扩展名
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I / usr / include / python2.6 -c helloworld.c -o build / temp.linux-x86_64-2.6 / helloworld.o
helloworld.c:4:20:错误:Python.h:无此类文件或目录
helloworld.c:5:26:错误:结构member.h:没有这样的文件或目录
helloworld.c:34:错误:'PyObject'之前的预期限定符列表
helloworld.c:121:错误:之前的预期限定符列表'PyObject'
helloworld.c:139:错误:预期')'在'*'令牌之前
helloworld.c:140:错误:预期'=',',',';',' asm或 __attribute__在 __pyx_PyInt_AsLongLong之前
helloworld.c:141:错误:预期在 __pyx_PyInt_AsUnsignedLongLong之前的 =,,,;, asm或 __attribute __
helloworld.c:142:错误:在'*'令牌
之前的预期')'helloworld.c:147:错误:在'*'令牌
之前的预期')'helloworld.c:148:错误: '*'令牌
helloworld.c:149之前的预期')':错误:预期*)令牌
helloworld.c:150之前的预期')':错误:'*'之前的预期')'令牌
helloworld.c:151:错误:在'*'之前的预期')'令牌
helloworld.c:152:错误:在'*'令牌之前的预期:')'令牌
helloworld.c :153:错误:'*'令牌
helloworld.c之前的预期')':c:154:错误:e在'*'令牌
helloworld.c:155之前xpected')':错误:预期')'在'*'令牌
helloworld.c:156:错误:预期')'在'*'之前令牌
helloworld.c:157:错误:预期的'*'在'*'之前令牌
helloworld.c:172:错误:预期的'=',',',';','asm'或'*'令牌
之前的'__attribute__'helloworld.c:173:错误:预期*令​​牌
之前的'=',',',';','asm'或'__attribute__' helloworld.c:174:错误:预期'=',',',';','asm'或'__attribute__'在'*'令牌
之前helloworld.c:181:错误:预期')'之前'*'令牌
helloworld.c:198:错误:预期在'*'令牌
helloworld.c:200之前的'=',',',';','asm'或'__attribute__' :错误:数组类型的元素类型不完整
helloworld.c:221:错误:'__pyx_kp_1'在这里未声明(不在函数中)
helloworld.c:221:警告:结构初始化器$中的多余元素b $ b helloworld.c:221:警告:(在'__pyx_string_tab [0]'初始化附近)
helloworld.c:221:警告:多余的元素i n结构初始化程序
helloworld.c:221:警告:(在'__pyx_string_tab [0]'的初始化附近)
helloworld.c:221:警告:结构初始化程序
helloworld.c中的多余元素:221:警告:('__pyx_string_tab [0]'的初始化附近)
helloworld.c:221:警告:结构初始化器
helloworld.c:221的警告元素:警告:(' __pyx_string_tab [0]')
helloworld.c:221:警告:结构体初始化程序
helloworld.c:221中的多余元素:警告:(在'__pyx_string_tab [0]'初始化附近)
helloworld.c:221:警告:结构初始值设定项
中的多余元素helloworld.c:221:警告:('__ pyx_string_tab [0]'的初始化附近)
helloworld.c:222:警告:多余的元素在结构初始化程序
helloworld.c:222中:警告:(在'__pyx_string_tab [1]'的初始化附近)
helloworld.c:222:警告:结构初始化程序
helloworld.c中的多余元素:222:警告:('__ pyx_string_tab [1]'的初始化附近)
helloworld.c:222:警告:结构体初始化程序中的多余元素
helloworld.c:222:警告:(在__pyx_string_tab [1]初始化附近)
helloworld.c:222:警告:结构初始值设定项
helloworld.c:222中的多余元素:警告:(__ pyx_string_tab [1]的附近初始化)
helloworld.c:222:警告:结构初始值设定项$ b $中的过量元素b helloworld.c:222:警告:(在__pyx_string_tab [1]的初始化附近)
helloworld.c:222:警告:结构初始化程序
helloworld.c:222中的多余元素:警告:( '__pyx_string_tab [1]'的初始化附近))
helloworld.c:237:错误:在'inithelloworld'
之前,预期为'=',',',';','asm'或'__attribute__' helloworld.c:238:错误:预期'=',',',';','asm'或'__attribute__'在'inithelloworld'
之前helloworld.c:305:错误:预期'=',' ,',';','asm'或'__attribute__'在'*'令牌
helloworld.c:313之前:错误:预期在'*'令牌
helloworld.c:379之前的')': 21:错误:补偿ile.h:没有这样的文件或目录
helloworld.c:380:25:错误:frameobject.h:没有这样的文件或目录
helloworld.c:381:23:错误:traceback.h:没有这样的文件或目录
helloworld.c:在函数'__Pyx_AddTraceback'中:
helloworld.c:384:错误:未声明'PyObject'(在此函数中首次使用)
helloworld.c: 384:错误:(每个未声明的标识符仅报告一次
helloworld.c:384:错误:出现在每个函数中。)
helloworld.c:384:错误:'py_srcfile'未声明(第一个在此函数中使用)
helloworld.c:385:错误:'py_funcname'未声明(此函数首次使用)
helloworld.c:386:错误:'py_globals'未声明(此函数中首次使用) )
helloworld.c:387:错误:未声明'empty_string'(此功能首次使用)
helloworld.c:388:错误:未声明'PyCodeObject'(此功能首次使用)
helloworld.c:388:错误:未声明 py_code(此功能首次使用)
helloworld.c:389:错误:'PyFrameObjec t'未声明(此函数首次使用)
helloworld.c:389:错误:'py_frame'未声明(此函数首次使用)
helloworld.c:392:警告:函数的隐式声明' PyString_FromString'
helloworld.c:399:警告:函数'PyString_FromFormat'
helloworld.c:412的隐式声明:警告:函数'PyModule_GetDict'的隐式声明
helloworld.c:412:错误:未声明 __pyx_m(在此函数中首次使用)
helloworld.c:415:警告:函数 PyString_FromStringAndSize的隐式声明
helloworld.c:420:警告:函数 PyCode_New的隐式声明'
helloworld.c:429:错误:'__ pyx_empty_tuple'未声明(此函数首次使用)
helloworld.c:440:警告:函数'PyFrame_New'的隐式声明
helloworld.c :441:警告:函数'PyThreadState_GET'的隐式声明
helloworld.c:448:警告:函数'PyTraceBack_Here'的隐式声明
helloworld.c:450:warni ng:函数'Py_XDECREF'的隐式声明
helloworld.c:在函数'__Pyx_InitStrings'中:
helloworld.c:458:错误:'__Pyx_StringTabEntry'没有名为'p'的成员
helloworld .c:460:错误:'__Pyx_StringTabEntry'没有名为'is_unicode'
helloworld.c:460:错误:'__Pyx_StringTabEntry'没有名为'is_identifier'成员
helloworld.c:461:错误:'__Pyx_StringTabEntry'没有名为'p'的成员
helloworld.c:461:警告:函数'PyUnicode_DecodeUTF8'的隐式声明
helloworld.c:461:错误:'__Pyx_StringTabEntry'没有名为' s'
helloworld.c:461:错误:'__Pyx_StringTabEntry'没有名为'n'的成员
helloworld.c:461:错误:'NULL'未声明(此功能首次使用)
helloworld.c:462:错误:'__Pyx_StringTabEntry'没有名为'intern'的成员
helloworld.c:463:错误:'__Pyx_StringTabEntry'没有名为'p'的成员
helloworld.c:463 :警告:函数'PyString_InternFromString的隐式声明'
helloworld.c:463:错误:'__Pyx_StringTabEntry'没有名为's'的成员
helloworld.c:465:错误:'__Pyx_StringTabEntry'没有名为'p'的成员.c:465:错误:'__Pyx_StringTabEntry'没有名为's'的成员
helloworld.c:465:错误:'__Pyx_StringTabEntry'没有名为'n'的成员
helloworld.c:476:错误:'__Pyx_StringTabEntry'没有名为'p'的成员
helloworld.c:在顶层:
helloworld.c:485:错误:在'*'令牌
helloworld之前是预期的')'。 c:494:错误:在*令牌
helloworld之前的预期')'。c:500:错误:在'__pyx_PyInt_AsLongLong之前的预期'=',',',';','asm'或'__attribute__' '
helloworld.c:516:错误:预期为'=',',',';','asm'或'__attribute__'在'__pyx_PyInt_AsUnsignedLongLong'之前
helloworld.c:538:错误:预期为')'在'*'令牌
helloworld.c:553:错误:预期')'在'*'令牌
helloworld.c:568:错误:预期')'在'*'令牌之前
helloworld.c:583:错误:预期为')'之前'*'令牌
helloworld.c:598:错误:预期')'在'*'令牌
helloworld.c:613:错误:预期')'在'*'令牌
之前helloworld.c:628:错误:在'*'令牌
之前的预期')'helloworld.c:643:错误:在**令牌
之前的预期')'helloworld.c:658:错误:在'*'令牌
helloworld.c:673之前的预期')':错误:预期')'在'*'令牌
helloworld.c:688:错误:预期的')'在'*'之前令牌
错误:命令'gcc'失败,退出状态为1

我有python和cython从Ubuntu 9.04存储库安装。我不知道为什么编译器找不到Python.h。



我尝试做:

  cython helloworld.pyx 

然后使用gcc手动编译结果:

  gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I / usr / include /python2.5 -o helloworld.so helloworld.c 

并得到相同的错误消息。 / p>

有任何线索吗?

解决方案

好像您缺少某些软件包像 python_dev 之类的东西-Debian和派生工具(包括Ubuntu)长期以来一直希望从包的各个部分中分离出所有可能被开发人员使用的东西这是针对每个人的……我可以对此进行辩论的哲学立场(并且已经对此进行了辩论,但在实践中并没有取得太大的成功),但可悲的是,这不能仅仅是忽略:-(


I'm trying to follow this tutorial from Cython: http://docs.cython.org/docs/tutorial.html#the-basics-of-cython and I'm having a problem.

The files are very simple. I have a helloworld.pyx:

print "Hello World"

and a setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)

and I compile it with the standard command:

python setup.py build_ext --inplace

I got the following error:

running build
running build_ext
building 'helloworld' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c helloworld.c -o build/temp.linux-x86_64-2.6/helloworld.o
helloworld.c:4:20: error: Python.h: No such file or directory
helloworld.c:5:26: error: structmember.h: No such file or directory
helloworld.c:34: error: expected specifier-qualifier-list before ‘PyObject’
helloworld.c:121: error: expected specifier-qualifier-list before ‘PyObject’
helloworld.c:139: error: expected ‘)’ before ‘*’ token
helloworld.c:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsLongLong’
helloworld.c:141: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsUnsignedLongLong’
helloworld.c:142: error: expected ‘)’ before ‘*’ token
helloworld.c:147: error: expected ‘)’ before ‘*’ token
helloworld.c:148: error: expected ‘)’ before ‘*’ token
helloworld.c:149: error: expected ‘)’ before ‘*’ token
helloworld.c:150: error: expected ‘)’ before ‘*’ token
helloworld.c:151: error: expected ‘)’ before ‘*’ token
helloworld.c:152: error: expected ‘)’ before ‘*’ token
helloworld.c:153: error: expected ‘)’ before ‘*’ token
helloworld.c:154: error: expected ‘)’ before ‘*’ token
helloworld.c:155: error: expected ‘)’ before ‘*’ token
helloworld.c:156: error: expected ‘)’ before ‘*’ token
helloworld.c:157: error: expected ‘)’ before ‘*’ token
helloworld.c:172: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:173: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:174: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:181: error: expected ‘)’ before ‘*’ token
helloworld.c:198: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:200: error: array type has incomplete element type
helloworld.c:221: error: ‘__pyx_kp_1’ undeclared here (not in a function)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:237: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘inithelloworld’
helloworld.c:238: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘inithelloworld’
helloworld.c:305: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:313: error: expected ‘)’ before ‘*’ token
helloworld.c:379:21: error: compile.h: No such file or directory
helloworld.c:380:25: error: frameobject.h: No such file or directory
helloworld.c:381:23: error: traceback.h: No such file or directory
helloworld.c: In function ‘__Pyx_AddTraceback’:
helloworld.c:384: error: ‘PyObject’ undeclared (first use in this function)
helloworld.c:384: error: (Each undeclared identifier is reported only once
helloworld.c:384: error: for each function it appears in.)
helloworld.c:384: error: ‘py_srcfile’ undeclared (first use in this function)
helloworld.c:385: error: ‘py_funcname’ undeclared (first use in this function)
helloworld.c:386: error: ‘py_globals’ undeclared (first use in this function)
helloworld.c:387: error: ‘empty_string’ undeclared (first use in this function)
helloworld.c:388: error: ‘PyCodeObject’ undeclared (first use in this function)
helloworld.c:388: error: ‘py_code’ undeclared (first use in this function)
helloworld.c:389: error: ‘PyFrameObject’ undeclared (first use in this function)
helloworld.c:389: error: ‘py_frame’ undeclared (first use in this function)
helloworld.c:392: warning: implicit declaration of function ‘PyString_FromString’
helloworld.c:399: warning: implicit declaration of function ‘PyString_FromFormat’
helloworld.c:412: warning: implicit declaration of function ‘PyModule_GetDict’
helloworld.c:412: error: ‘__pyx_m’ undeclared (first use in this function)
helloworld.c:415: warning: implicit declaration of function ‘PyString_FromStringAndSize’
helloworld.c:420: warning: implicit declaration of function ‘PyCode_New’
helloworld.c:429: error: ‘__pyx_empty_tuple’ undeclared (first use in this function)
helloworld.c:440: warning: implicit declaration of function ‘PyFrame_New’
helloworld.c:441: warning: implicit declaration of function ‘PyThreadState_GET’
helloworld.c:448: warning: implicit declaration of function ‘PyTraceBack_Here’
helloworld.c:450: warning: implicit declaration of function ‘Py_XDECREF’
helloworld.c: In function ‘__Pyx_InitStrings’:
helloworld.c:458: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:460: error: ‘__Pyx_StringTabEntry’ has no member named ‘is_unicode’
helloworld.c:460: error: ‘__Pyx_StringTabEntry’ has no member named ‘is_identifier’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:461: warning: implicit declaration of function ‘PyUnicode_DecodeUTF8’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘n’
helloworld.c:461: error: ‘NULL’ undeclared (first use in this function)
helloworld.c:462: error: ‘__Pyx_StringTabEntry’ has no member named ‘intern’
helloworld.c:463: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:463: warning: implicit declaration of function ‘PyString_InternFromString’
helloworld.c:463: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘n’
helloworld.c:476: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c: At top level:
helloworld.c:485: error: expected ‘)’ before ‘*’ token
helloworld.c:494: error: expected ‘)’ before ‘*’ token
helloworld.c:500: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsLongLong’
helloworld.c:516: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsUnsignedLongLong’
helloworld.c:538: error: expected ‘)’ before ‘*’ token
helloworld.c:553: error: expected ‘)’ before ‘*’ token
helloworld.c:568: error: expected ‘)’ before ‘*’ token
helloworld.c:583: error: expected ‘)’ before ‘*’ token
helloworld.c:598: error: expected ‘)’ before ‘*’ token
helloworld.c:613: error: expected ‘)’ before ‘*’ token
helloworld.c:628: error: expected ‘)’ before ‘*’ token
helloworld.c:643: error: expected ‘)’ before ‘*’ token
helloworld.c:658: error: expected ‘)’ before ‘*’ token
helloworld.c:673: error: expected ‘)’ before ‘*’ token
helloworld.c:688: error: expected ‘)’ before ‘*’ token
error: command 'gcc' failed with exit status 1

I have python and cython installed from Ubuntu 9.04 repositories. I can't figure why the compiler can't find Python.h.

I tried doing:

cython helloworld.pyx

and then compiling the result manually with gcc:

gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.5 -o helloworld.so helloworld.c

and got the same exact error message.

Any clues?

解决方案

Looks like you're missing some package like python_dev or the like -- Debian and derivatives (including Ubuntu) have long preferred to isolate everything that could possibly be of "developer"'s use from the parts of a package that are for "everybody"... a philosophical stance I could debate against (and have debated against, without much practical success, in mahy fora), but one that, sadly, can't just be ignored:-(

这篇关于Cython Wiki的Hello World的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆