Linux环境下ONNX安装失败问题求助
解决Ubuntu 18.04 + Python3.6下ONNX安装的编译问题
问题现象
1. Protobuf相关编译错误
执行python3 -m pip install onnx时出现如下编译错误:
/tmp/pip-install-7ajubmjo/onnx_08cda1ef5f1d460ab7b455210cf3083e/onnx/defs/sequence/defs.cc: In function ‘bool onnx::BuildSequenceMapBodyFunc(const onnx::FunctionBodyBuildContext&, const onnx::OpSchema&, onnx::FunctionProto&)’: /tmp/pip-install-7ajubmjo/onnx_08cda1ef5f1d460ab7b455210cf3083e/onnx/defs/sequence/defs.cc:675:40: error: no match for ‘operator[]’ (operand types are ‘google::protobuf::RepeatedPtrField<onnx::ValueInfoProto>’ and ‘int’) seq_at_node.add_output(g_inputs[inputIndex].name()); [ 95%] Building CXX object CMakeFiles/onnx.dir/onnx/version_converter/helper.cc.o CMakeFiles/onnx.dir/build.make:830: recipe for target 'CMakeFiles/onnx.dir/onnx/defs/sequence/defs.cc.o' failed
2. pybind11无法被CMake识别
编译过程中提示找不到pybind11,尽管已通过pip install pybind11安装:
Generated: /tmp/pip-install-7ajubmjo/onnx_08cda1ef5f1d460ab7b455210cf3083e/.setuptools-cmake-build/onnx/onnx-ml.proto Generated: /tmp/pip-install-7ajubmjo/onnx_08cda1ef5f1d460ab7b455210cf3083e/.setuptools-cmake-build/onnx/onnx-operators-ml.proto Generated: /tmp/pip-install-7ajubmjo/onnx_08cda1ef5f1d460ab7b455210cf3083e/.setuptools-cmake-build/onnx/onnx-data.proto -- Could NOT find pybind11 (missing: pybind11_DIR) -- pybind11 v2.9.1 -- -- ******** Summary ******** -- CMake version : 3.10.2 -- CMake command : /usr/bin/cmake -- System : Linux -- C++ compiler : /usr/bin/c++ -- C++ compiler version : 7.5.0 -- CXX flags : -Wnon-virtual-dtor
环境信息
- Python 3.6
- Ubuntu 18.04
- Protobuf通过
sudo apt-get install protobuf-compiler libprotobuf-dev安装 - pybind11通过
pip install pybind11安装
解决方案
1. 修复Protobuf版本不兼容问题
Ubuntu 18.04默认apt源的protobuf版本过低(3.0.x),与ONNX编译要求不匹配,需手动安装兼容版本:
- 卸载系统自带的protobuf:
sudo apt-get remove --purge protobuf-compiler libprotobuf-dev sudo apt-get autoremove - 下载并编译安装protobuf 3.20.3(适配Python3.6和ONNX的稳定版本):
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protobuf-all-3.20.3.tar.gz tar -zxvf protobuf-all-3.20.3.tar.gz cd protobuf-all-3.20.3 ./configure --prefix=/usr/local make -j$(nproc) sudo make install sudo ldconfig - 验证安装结果:
输出应为protoc --versionlibprotoc 3.20.3
2. 解决pybind11识别问题
pip安装的pybind11无法被系统CMake检测到,安装系统级开发包即可:
sudo apt-get install pybind11-dev
3. 重新安装ONNX
清理缓存后安装适配版本:
pip3 uninstall -y onnx pip3 cache purge python3 -m pip install onnx==1.13.1
内容的提问来源于stack exchange,提问作者external
相关产品推荐
相关产品推荐

