Best way to embed Python in C++ Application?


Now, I’m fully aware this is discussed in the docs, however, I’d like a little information about extending and embedding when it comes to Panda in particular and what the best practices are. I have a general idea of what seems to be the accepted practice, which is writing the most of the application in python and writing performance critical bits in C++.

Though that makes sense in the sense of extending python applications with C++, one of my goals is to make my Panda3D application python scriptable. There are a few sources I found on doing this, but they all are rather old or bare. What is the best practice when it comes to making a C++ application python scriptable?

Also, sorry if this is not the right section for this, it seemed most appropriate.


I’m not sure that there is a best practice when it comes to Panda3D in specific. I don’t think there are considerations that relate to Panda3D in particular, other than how you interface with Panda’s Python bindings (but all that should work as long as they are available and linked against the same DLLs).

Statically linking the Python bindings is a theoretical option, but will require a little extra glue. The best way to do that might be to extend the Python inittab with the panda3d modules by passing in their PyInit functions, which you will have to declare as externs. Then they will become available as “builtin modules” to the interpreter.

Important to note is that on Linux, if you don’t link the bindings statically, you will have to link your application with the -rdynamic flag to make sure that the Python interpreter symbols become available to loaded dynamic modules.