Calling python from a c++ program for distribution


Question

I would like to call python script files from my c++ program.

I am not sure that the people I will distribute to will have python installed.

Basically I'm looking for a .lib file that I can use that has an Apache like distribution license.

1
44
11/18/2008 7:53:40 PM

Accepted Answer

Boost has a python interface library which could help you.

Boost.Python

30
11/10/2015 10:04:39 PM

I would like to call python script files from my c++ program.

This means that you want to embed Python in your C++ application. As mentioned in Embedding Python in Another Application:

Embedding Python is similar to extending it, but not quite. The difference is that when you extend Python, the main program of the application is still the Python interpreter, while if you embed Python, the main program may have nothing to do with Python — instead, some parts of the application occasionally call the Python interpreter to run some Python code.

I suggest that you first go through Embedding Python in Another Application. Then refer the following examples

  1. Embedding Python in C/C++: Part I

  2. Embedding Python in C/C++: Part II

  3. Embedding Python in Multi-Threaded C/C++ Applications

If you like Boost.Python, you may visit the following links:

  1. Embedding Python with Boost.Python Part 1

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon