How to enable `--embed` with cythonize?

When called cythonon the command line, you can tell him to create a method int main()that implements the Python interpreter:

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

However, when you are import Cythondirectly, for example. from the distutils setup.pyscript parameter embedseems 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 am I doing wrong here?

+1
source share
1 answer

I understood this from Keaton sources.

It looks like Cython is expecting a specific value for Options.embed:

Options.embed = "main"
+3
source

Source: https://habr.com/ru/post/1687774/


All Articles