[英]pybind11 crashes (segmentation fault (core dumped)) while importing ONNX python module
我在我的 C++ 代碼中使用 pybind11。 當我嘗試導入onnx
時,我的代碼因Segmentation fault (core dumped)
而崩潰。 但是,如果我導入onnxruntime
,一切都很好。 當然onnx
和onnxruntime
都是通過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
導入行的順序無關緊要。 無論在哪里, py::module::import("onnx")
因分段錯誤而崩潰。 如何成功運行py::module::import("onnx")
?
我正在回答我自己的問題。 問題的原因是onnx
與protobuf
版本 3.19.0 或更高版本不兼容。 在 3.18.1 和 3.12.0 之間使用protobuf
將解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.