プロジェクトの一部、特にPython /C++インターフェイスをリファクタリングしようとしています。標準のboost::python python初期化は以前は機能していました:
boost::python::object main_module = boost::python::import("__main__");
boost::python::object globals(main_module.attr("__dict__"));
//..。
しかし、それを独自のクラスに分解した後、私は
TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies>
以下のように、PyInterfaceオブジェクトをインスタンス化する場合:
namespace py = boost::python;
class PyInterface
{
private:
py::object
main_module,
global,
tmp;
//...
public:
PyInterface();
//...
};
PyInterface::PyInterface()
{
std::cout << "Initializing..." << std::endl;
Py_Initialize();
std::cout << "Accessing main module..." << std::endl;
main_module = py::import("__main__");
std::cout << "Retrieve global namespace..." << std::endl;
global(main_module.attr("__dict__"));
//...
}
//in test.cpp
int main()
{
PyInterface python;
//...
}
Running gives the following output:
Initializing...
Accessing main module...
Retrieving global namespace...
TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies>
私が考えることができる唯一のことは、それを使用する前に「グローバル」を宣言することと関係があるということです。その場合、私がこれを行うことができる別の方法はありますか?