如何使用cythonize启用`--embed`? [英] How to enable `--embed` with cythonize?
本文介绍了如何使用cythonize启用`--embed`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在命令行上调用 cython
时,可以告诉它创建 int main()
方法内嵌Python解释器:
When calling cython
on the command line, it's possible to tell it to create a int main()
method that embeds the Python interpreter:
$ cython --embed main.pyx
$ grep 'int main' main.c
int main(int argc, char** argv) {
但是,当您直接导入Cython
,例如从 distutils
setup.py
脚本中,选择 embed
选项似乎被忽略了:
However, when you import Cython
directly, e.g. from a distutils
setup.py
script, the embed
option seems to be ignored:
$ 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
$
这是什么我在这里做错了吗?
What is it that I'm doing wrong here?
推荐答案
我从Cython的消息来源中弄清楚了。
I figured it out from Cython's sources.
似乎Cython期望 Options.embed
的特定值:
It looks like Cython expects a specific value for Options.embed
:
Options.embed = "main"
这篇关于如何使用cythonize启用`--embed`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文