【问题标题】:How to enable `--embed` with cythonize?如何使用 cythonize 启用 `--embed`?
【发布时间】:2015-09-27 05:16:10
【问题描述】:

在命令行上调用cython 时,可以告诉它创建一个嵌入Python 解释器的int main() 方法:

$ cython --embed main.pyx
$ grep 'int main' main.c
int main(int argc, char** argv) {

但是,当您直接import Cython 时,例如在 distutils setup.py 脚本中,embed 选项似乎被忽略了:

$ python3
>>> from Cython.Compiler import Options
>>> Options.embed = True
>>> from Cython.Build import cythonize
>>> cythonize('main.pyx')
[1/1] Cythonizing main.pyx
>>>
$ grep 'int main' main.c
$

我在这里做错了什么?

【问题讨论】:

    标签: python cython


    【解决方案1】:

    我从 Cython 的消息来源得知。

    看起来 Cython 需要 Options.embed 的特定值:

    Options.embed = "main"
    

    【讨论】:

      猜你喜欢
      • 2019-11-17
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      • 2011-10-02
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多