2009-07-28 3 views
2

Я пытаюсь следовать этому руководству от Cython: http://docs.cython.org/docs/tutorial.html#the-basics-of-cython, и у меня возникла проблема.Hello World from cython wiki не работает

Файлы очень просты. У меня есть helloworld.pyx:

print "Hello World" 

и 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"])] 
) 

и я скомпилировать его стандартной командой:

python setup.py build_ext --inplace 

Я получил следующее сообщение об ошибке:

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 

У меня есть python и c ython установлен из репозиториев 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 

и получил то же точное сообщение об ошибке.

Любые подсказки?

+0

Вы проверили вручную, что '/ usr/include/python2.6/Python.h' существует? –

ответ

4

Похоже, что вам не хватает какого-либо пакета, такого как python_dev или тому подобного. Debian и его производные (включая Ubuntu) уже давно предпочитают изолировать все, что может быть связано с «разработчиком» от частей пакета, которые для «всех» ... философская позиция, которую я мог бы обсуждать против (и : обсуждали без особого практического успеха в махи-форе), но тот, к сожалению, нельзя просто игнорировать :-(

1

Ой блин ... забудь ...

Я забыл установить пакеты Dev.

Duh. Глупый. Извините ребята.

Смежные вопросы