1
私は私のプロジェクトの一部、特にPython/C++インターフェイスをリファクタリングしようとしています。 標準ブースト::のpythonのpythonの初期化が前に働いていた。しかし、それ自身のクラスにそれを因数分解した後、私はBoost :: Python Forward宣言boost :: python :: object throw python TypeError
TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy<boost::python::api::attribute_policies>
を取得しています
boost::python::object main_module = boost::python::import("__main__");
boost::python::object globals(main_module.attr("__dict__"));
// ...
以下のように、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>
私が考えることができるのは、それを使用する前に「グローバル」を宣言することと関係があることだけです。この場合、私はこれを行うことができる別の方法がありますか?