Could PyOxidizer help embedding Python into a C/C++ app?

65 views
Skip to first unread message

Super Twang

unread,
Aug 3, 2019, 9:11:57 PM8/3/19
to pyoxidizer-users
Hi y'all,

Does anyone know if PyOxidixer could wrap Pythin up into an interpreter that would be embedded into a C/C++ app?

Thanks for any thoughts.

Best,
ST

Gregory Szorc

unread,
Aug 5, 2019, 10:55:33 PM8/5/19
to Super Twang, pyoxidizer-users
Yes, this is definitely doable.

It should be possible to use PyOxidizer's build system to construct a static or shared library which you could then consume from your C/C++ application's build system. Simply invoke e.g. `pyoxidizer build-library` to produce a library and add e.g. `-lembeddedpython` to your application's linker arguments and things should "just work." Alternatively, you could hack up the generated Cargo.toml to produce a library instead of an application and then hook that library up to your C/C++ application's build system. Alternatively, you could configure the Rust application to link your C/C++ application and then call into its main(). This would have Rust/Cargo handle all the linking bits. There's tons of options. All of them probably doable today without modifying PyOxidizer's source code. But we should get something documented so it is minimal effort for others.

The only real complexity here is with loading modules from memory. That requires custom Rust code that isn't part of the Python distribution itself. If you want to fully embed a Python interpreter into a C/C++ application, you could consume the libpython static library in the Python distributions used by PyOxidizer. To get in memory import will require executing some Rust code in addition to what's in the Python distribution.

--
You received this message because you are subscribed to the Google Groups "pyoxidizer-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyoxidizer-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyoxidizer-users/0b7b781d-6821-488a-a92e-0cba2060e80b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages