I am using pybind11 in my C++ code. When I try to import onnx
, my code crashes with Segmentation fault (core dumped)
. However, if I import onnxruntime
, everything is well. Of course both onnx
and onnxruntime
are installed on my system via pip
.
// installed libraries pip install onnx pip install onnxruntime
// C++ code #include <pybind11/embed.h> namespace py = pybind11; py::module::import("onnxruntime"); // This is okay py::module::import("onnx"); // This crashes with segmentation fault
The order of the import lines is irrelevant. Wherever it is, py::module::import("onnx")
crashes with segmentation fault. How can I successfully run py::module::import("onnx")
?
Advertisement
Answer
I am answering my own question. The cause of the problem was that onnx
was not compatible with protobuf
version 3.19.0 or higher. Using protobuf
between 3.18.1 and 3.12.0 will solve the problem.