[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Embedding Python in C

Jesse Ibarra schrieb am 17.07.19 um 20:39:
> My options seem rather limited, I need to make a Pipeline from
> (Smalltalk -> C -> Python) then go back (Smalltalk <- C <- Python).
> Since Smalltalk does not support Python directly I have to settle with
> the C/Python API
> (https://docs.python.org/3.6/extending/embedding.html#beyond-very-high-level-embedding-an-overview).
> Any suggestions?

First of all: don't use the C-API! :-)

Use Cython instead. It's a Python-to-C compiler that covers up all the ugly
little details of talking to Python from C (importing a module is just
"import module", and it even adapts to different Python versions
automatically). You can keep writing Python code, and at the same time
trivially use external C code.



For embedding Python in an external program (in case you really need to do
that and can't live with starting Python instead of Smalltalk), here's an


It uses the "--embed" argument to Cython that generates a C (main) function
to start up the CPython runtime.