2013-10-04 42 views
8

在使用時用Cython創建從helloworld.pyx helloworld.c,這個錯誤發生:用Cython錯誤與打印功能編譯參數

error compiling Cython file: 
------------------------------------------------------------ 
... 
print('hello world',end='') 
        ^
------------------------------------------------------------ 

p21.pyx:1:23: Expected ')', found '=' 

我的命令來創建helloworld.c是:

cython3 --embed p21.pyx 

回答

5

它看起來像cython默認將所有打印作爲python 2語句處理。爲了使用您需要從未來模塊導入它的巨蟒-3打印功能:

from __future__ import print_function 

print('hello world',end='') 
3

我不知道這是不是仍然相關,但在我的情況下,用Cython 0.23,編譯您必須通過Python3代碼標誌-3。例如,在代碼

cython -3 mycode.py