(After looking into the documentation, examples, etc I could not solve myself)
I have a small module mymodule which does wrap my class MyClass and seems to work fine in basic tests.
Then I want to use this module embedding python with pybind11/embed.h and passing from C++ to python an object instance of MyClass that will be used in a script loaded later on in my application.
The following simple snipped is what I used for try things out
py::scoped_interpreter guard{};
auto obj = std::make_shared<MyClass>(MyClass());
py::object mm = py::module::import("mymodule").attr("__dict__");
py::object pyobj = py::cast(obj, py::return_value_policy::reference);
mm["obj"] = pyobj;
py::eval_file("myscript.py"); // this script uses obj
and it seems to work fine.
However, when I apply this in my "real" application, when mm["obj"] = pyobj I get
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): TypeError: Unregistered type : MyClass
and I can't figure it out why this is the case? Does anyone have a tips/hint to investigate this...?
(After looking into the documentation, examples, etc I could not solve myself)
I have a small module
mymodule
which does wrap my classMyClass
and seems to work fine in basic tests.Then I want to use this module embedding python with
pybind11/embed.h
and passing fromC++
topython
an object instance ofMyClass
that will be used in a script loaded later on in my application.The following simple snipped is what I used for try things out
and it seems to work fine.
However, when I apply this in my "real" application, when
mm["obj"] = pyobj
I getand I can't figure it out why this is the case? Does anyone have a tips/hint to investigate this...?
Thanks!