该%%cython
命令非常方便地创建 cython 函数,而无需构建和使用包。该命令有几个选项,但我找不到在那里指定编译时环境变量的方法。
我想要相当于:
from Cython.Distutils.extension import Extension
ext = Extension(...
cython_compile_time_env={'MYVAR': 10},
...)
为%%cython
命令。
我已经尝试过:
%%cython -cython_compile_time_env={'MYVAR':10}
IF MYVAR:
def func():
return 1
ELSE:
def func():
return 2
但这会引发异常:
Error compiling Cython file:
------------------------------------------------------------
...
IF MYVAR:
^
------------------------------------------------------------
...\.ipython\cython\_cython_magic_28df41ea67fec254f0be4fc74f7a6a54.pyx:2:8: Compile-time name 'MYVAR' not defined
和
%%cython --cython_compile_time_env={'MYVAR':10}
IF MYVAR:
def func():
return 1
ELSE:
def func():
return 2
投掷
UsageError:无法识别的参数:--cython_compile_time_env={'MYVAR':10}