Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed Python/Numpy/Matplotlib in a C++ Qt application?

I am currently working on a small C++ Qt 4.8 (and 5.0 when it will be released) scientific application, and I would like to know if it is possible to embed Python+Numpy+Maptplotlib (and to have a portable app even for people without Python installed) in a C++ Qt application in order to make beautiful plots inside my application ?

Is there any tutorial / example available of a such thing ?

Thank you very much.

P.S. : it is not a problem for me to have to generate temporary files, but it is important that the user doesn't have to have already python installed.

like image 796
Vincent Avatar asked Jun 30 '12 15:06

Vincent


1 Answers

The common way to deal with Python from C++ is with Boost.Python, but it is possible to get along without it.

What you need to remember is that the "Python interpreter" consists of two parts: The Python DLL/SO and the Python stdlib, both of which you will need to provide. The only things a Python installation adds is configuration and an executable which is only a thin wrapper around the other three parts.

Since you don't have a configuration, once the interpreter is initialized you will need to use PySys_SetPath() to set sys.path to point to the stdlib and any additional packages. From there you can use the rest of the C API to manipulate the interpreter as you would with a native installation.

like image 175
Ignacio Vazquez-Abrams Avatar answered Sep 22 '22 12:09

Ignacio Vazquez-Abrams