Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用打印函数参数编译cython时出错_Python 3.x_Cython - Fatal编程技术网

Python 3.x 使用打印函数参数编译cython时出错

Python 3.x 使用打印函数参数编译cython时出错,python-3.x,cython,Python 3.x,Cython,使用cython从helloworld.pyx创建helloworld.c时,出现以下错误: error compiling Cython file: ------------------------------------------------------------ ... print('hello world',end='') ^ -----------------------------------------------------

使用cython从helloworld.pyx创建helloworld.c时,出现以下错误:

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

p21.pyx:1:23: Expected ')', found '='
我创建helloworld.c的命令是:

cython3 --embed p21.pyx

看起来cython在默认情况下将所有打印处理为python 2语句。要使用python 3打印功能,您需要从future模块导入它:

from __future__ import print_function

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

我不知道这是否仍然相关,但在我的例子中,对于cython 0.23,要编译Python3代码,必须传递标志
-3
。比如说

cython -3 mycode.py

Cython默认为Python 2语义。将语言级别设置为3,可通过以下注释完成:

#cython: language_level=3

ref:

在我看来,这是最好的答案,因为它不需要修改任何源文件。