<p>I would like to call python script files from my c++ program.</p>
<p>I am not sure that the people I will distribute to will have python installed.</p>

[{'answer_id': 49148, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 6, 'selected': True, 'text': '<p>Boost has a python interface library which could help you.</p>\n\n<p><a href="http://www.boost.org/doc/libs/release/libs/python/doc/index.html" rel="noreferrer">Boost.Python</a></p>\n'}, {'answer_id': 49319, 'author': 'David Dibben', 'author_id': 5022, 'author_profile': 'https://Stackoverflow.com/users/5022', 'pm_score': 2, 'selected': False, 'text': '<p>Embeding the Python interpreter inside your C++ app will let you run Python programs using your application run Python scripts. It will also make it easier possible for those scripts to call C++ functions in your application. If this is what you want then the Boost library mentioned previously may be what you want to make it easier to create the link. In the past I have used <a href="http://www.swig.org/" rel="nofollow noreferrer">SWIG</a> to generate Python interfaces to C++ code. It was not clear from your question whether you wanted the Python scripts to call your C++ program or whether you just wanted the C++ to call Python.</p>\n\n<p>Many of the Python functions use modules which are not built into the Python interpreter. If your Python scripts call these functions then you will either need to have your users install Python or include the python runtime files with your application. It will depend on what modules you import in you Python scripts.</p>\n'}, {'answer_id': 49439, 'author': 'Tony Meyer', 'author_id': 4966, 'author_profile': 'https://Stackoverflow.com/users/4966', 'pm_score': 2, 'selected': False, 'text': '<p>Boost is probably the best choice, however if you\'re wanting something that\'s more standalone, and if this is for use with Windows (which seems feasible given that they are the people least likely to have Python installed), then you can use <a href="http://www.py2exe.org" rel="nofollow noreferrer">py2exe</a> to create a DLL with entry points suitable for COM objects.  You can then interface with the library via COM.  (Obviously this is not at all useful as a cross-platform solution).</p>\n'}, {'answer_id': 328451, 'author': 'bhadra', 'author_id': 30289, 'author_profile': 'https://Stackoverflow.com/users/30289', 'pm_score': 6, 'selected': False, 'text': '<blockquote>\n<p>I would like to call python script files from my c++ program.</p>\n</blockquote>\n<p>This means that you want to embed Python in your C++ application. As mentioned in <a href="http://docs.python.org/extending/embedding.html" rel="nofollow noreferrer">Embedding Python in Another Application</a>:</p>\n<blockquote>\n<p>Embedding Python is similar to\nextending it, but not quite. The\ndifference is that when you extend\nPython, the main program of the\napplication is still the Python\ninterpreter, while if you embed\nPython, the main program may have\nnothing to do with Python — instead,\nsome parts of the application\noccasionally call the Python\ninterpreter to run some Python code.</p>\n</blockquote>\n<p>I suggest that you first go through <a href="http://docs.python.org/extending/embedding.html" rel="nofollow noreferrer">Embedding Python in Another Application</a>. Then refer the following examples</p>\n<ol>\n<li><p><a href="http://www.codeproject.com/KB/cpp/embedpython_1.aspx" rel="nofollow noreferrer">Embedding Python in C/C++: Part I</a></p>\n</li>\n<li><p><a href="http://www.codeproject.com/KB/cpp/embedpython_2.aspx" rel="nofollow noreferrer">Embedding Python in C/C++: Part II</a></p>\n</li>\n<li><p><a href="http://www.linuxjournal.com/article/3641" rel="nofollow noreferrer">Embedding Python in Multi-Threaded C/C++ Applications</a></p>\n</li>\n</ol>\n<p>If you like <a href="https://www.boost.org/doc/libs/1_71_0/libs/python/doc/html/reference/embedding.html" rel="nofollow noreferrer">Boost.Python</a>, you may visit the following links:</p>\n<ol>\n<li><a href="https://www.boost.org/doc/libs/1_77_0/libs/python/doc/html/tutorial/tutorial/embedding.html" rel="nofollow noreferrer">Embedding Python with Boost.Python Part 1</a></li>\n</ol>\n'}, {'answer_id': 53325201, 'author': 'ingomueller.net', 'author_id': 651937, 'author_profile': 'https://Stackoverflow.com/users/651937', 'pm_score': 5, 'selected': False, 'text': '<p>Interestingly, nobody has mentioned <a href="https://pybind11.readthedocs.io/" rel="noreferrer">pybind11</a>, yet. From their documentation:</p>\n\n<blockquote>\n  <p>pybind11 is a lightweight header-only library that exposes C++ types\n  in Python and vice versa, mainly to create Python bindings of existing\n  C++ code. Its goals and syntax are similar to the excellent\n  Boost.Python library by David Abrahams: to minimize boilerplate code\n  in traditional extension modules by inferring type information using\n  compile-time introspection. [...] Since its creation, this library has\n  grown beyond Boost.Python in many ways, leading to dramatically\n  simpler binding code in many common situations.</p>\n</blockquote>\n\n<p>Concretely, calling into a Python function (called embedding) is as simple as this (taken from the <a href="https://pybind11.readthedocs.io/en/stable/advanced/embedding.html" rel="noreferrer">documentation</a>):</p>\n\n<pre><code>#include &lt;pybind11/embed.h&gt; // everything needed for embedding\nnamespace py = pybind11;\n\nint main() {\n    py::scoped_interpreter guard{}; // start the interpreter and keep it alive\n    py::print("Hello, World!"); // use the Python API\n}\n</code></pre>\n'}, {'answer_id': 54383046, 'author': 'RiteshC', 'author_id': 7864743, 'author_profile': 'https://Stackoverflow.com/users/7864743', 'pm_score': 3, 'selected': False, 'text': '<p>Use system call to run a python script from C++</p>\n\n<pre><code>#include&lt;iostream&gt;\n#include &lt;cstdlib&gt;\nusing namespace std;\nint main ()\n{\nint result = system("/usr/bin/python3 testGen1.py 1");\ncout &lt;&lt; result; \n}\n</code></pre>\n'}, {'answer_id': 69672216, 'author': 'Yahya Tawil', 'author_id': 7664449, 'author_profile': 'https://Stackoverflow.com/users/7664449', 'pm_score': -1, 'selected': False, 'text': '<p>Using Inter Process Communication (IPC) over socket can be a possible solution. Use a local network socket to listen/trasfer commands between both.</p>\n'}]
['https://Stackoverflow.com/questions/49137', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3153/']