Cython编译器指令的language_level未被遵守。

7

我正在使用Cython的编译器指令(http://docs.cython.org/en/latest/src/reference/compilation.html#globally)。

$ cat temp.pyx
# cython: language_level=3
print("abc", "def", sep=" ,") # invalid in python 2

编译:

$ cythonize -i world_dep.pyx
Error compiling Cython file:
------------------------------------------------------------
...
# cython: language_level=3


print("abc", "def", sep=" ,")                      ^
------------------------------------------------------------

temp.pyx:4:23: Expected ')', found '='

因此,language_level指令未被遵守。因此,cythonize最终使用Python 2语义,并且由于上面的打印语句在Python 2中无效,因此会抛出错误。

但是,包括任何Python语句都可以使其正常工作:

 $ cat temp.pyx
 # cython: language_level=3
 import os
 print("abc", "def", sep=" ,")

编译和执行:

$ cythonize -i temp.pyx; python -c "import temp"
abc, def

有没有想法 import 语句是如何使language_level被尊重的?
我已经在 Cython GitHub 存储库上提出了这个问题

我猜测这个Cython GitHub存储库上的问题是你提出的吗? - user707650
@Evert - 是的。为了未来读者,将GitHub问题添加到问题中。 - Saim Raza
1
这个问题已经在五月底得到了修复(请参见问题)。 - handle
1个回答

2

如评论所说,这个bug已经被修复


$ /mnt/c/Python36/Scripts/cython.exe --version
Cython version 0.29.8
$ /mnt/c/Python36/Scripts/cythonize.exe -a -i temp.pyx
Compiling C:\Users\name\Documents\code\benchmark\temp.pyx because it changed.
[1/1] Cythonizing C:\Users\name\Documents\code\benchmark\temp.pyx
running build_ext
building 'temp' extension
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code
creating C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code\benchmark
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\name\appdata\local\programs\python\python36\inc
lude -Ic:\users\name\appdata\local\programs\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows K
its\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)
\Windows Kits\8.1\include\winrt" /TcC:\Users\name\Documents\code\benchmark\temp.c /FoC:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents
\code\benchmark\temp.obj
temp.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\users\e1220
41\appdata\local\programs\python\python36\libs /LIBPATH:c:\users\name\appdata\local\programs\python\python36\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visu
al Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64
" /EXPORT:PyInit_temp C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code\benchmark\temp.obj /OUT:C:\Users\name\Documents\code\benc
hmark\temp.cp36-win_amd64.pyd /IMPLIB:C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code\benchmark\temp.cp36-win_amd64.lib
temp.obj : warning LNK4197: export 'PyInit_temp' specified multiple times; using first specification
   Creating library C:\Users\name\Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code\benchmark\temp.cp36-win_amd64.lib and object C:\Users\name\
Documents\code\benchmark\tmpw0giz82d\Release\Users\name\Documents\code\benchmark\temp.cp36-win_amd64.exp
Generating code
Finished generating code

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接