7

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.

1
  • Not that I've seen, but there aren't too many steps. Commented Jun 30, 2012 at 16:11

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That gets you a Python interpreter. Now please add how to also provide NumPy and Matplotlib.
You... put them in a directory and add it to sys.path. That part doesn't change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.