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 语义,并且由于上面的 print 语句在 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 存储库上提出了同样的问题?

4

1 回答 1

2

如评论所述,此错误已修复

$ /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
于 2019-06-04T15:13:49.097 回答