Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable `--embed` with cythonize?

Tags:

python

cython

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) {

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?

like image 273
mic_e Avatar asked Dec 24 '22 17:12

mic_e


1 Answers

I figured it out from Cython's sources.

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

Options.embed = "main"
like image 164
mic_e Avatar answered Jan 08 '23 02:01

mic_e