I am writing a python embedding in C++ application. The related code snippet that I declare the module of python(user-defined one) that needs to be embedded as below:
boost::python::object main_module = boost::python::import("__main__");
boost::python::object main_namespace = main_module.attr("__dict__");
boost::python::exec("import python_module", main_namespace); //This line is the culprit
However, I'm stuck when I receive the following error:
terminate called after throwing an instance of 'boost::python::error_already_set'
My user-defined python module resides in the same directory as my C++ code. When I try like to use numpythat works, the problem is that only with my user-defined one, it doesn't. What could be done in order to debug it?
EDIT:
After I include the code in try/catch block, I obtained the following compile error:
ImportError: No module named python_module
I also try to add this:
boost::python::exec("import sys; sys.path.append('/path/to/python_module.py');", main_namespace);
boost::python::exec("import python_module", main_namespace);
but not yet working.
The problem now is how do I make it known to my C++ code?