python - 如何使用 cythonize 启用 `--embed`?

标签 python cython

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

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

但是,当您直接导入 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
$

我这里做错了什么?

最佳答案

我从 Cython 的资源中弄明白了。

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

Options.embed = "main"

关于python - 如何使用 cythonize 启用 `--embed`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31307169/

相关文章:

python - 在 Python 中编辑 Mozilla 配置文件

python 或 bash 脚本将文件夹中的所有文件传递到 java 命令行

python - 如何让 ttk.Scale 表现得更像 tk.Scale?

Python:获取两个多维数组的点积

python - randomkit.h 发生了什么或如何迁移到最新的 numpy.random c/cython api

python - cython 函数输出与 python 函数输出略有不同

python - 使用 setup.py Cythonize 但不编译 .pyx 文件

python - 将 netcdf 文件中的所有变量和维度从 int/float 转换为 double

python - 在cython中声明一个类的实例

linux - Cython:从python调用的cdef函数调用扩展类型cdef方法