protocol-buffers - nanopb 在 protobuf 中的编译问题
问题描述
我正在使用 nanopb 库
我寻求您的建议来解决构建问题 - 我正在使用 protobuf 3.12,nanopb 0.4.2, puython3,gcc 。我编译了 c 和 python 的 protoc,但在构建时仍然遇到问题。
make
protoc -osimple.pb simple.proto - step done
nanopb/examples/simple $ python ../../generator/nanopb_generator.py simple.pb -> following error
$ python3 ../../generator/nanopb_generator.py simple.pb Traceback (most recent call last): File "../../generator/nanopb_generator.py", line 50, in from .proto import nanopb_pb2 SystemError: Parent module '' not loaded, cannot perform relative import
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "../../generator/nanopb_generator.py", line 71, in import proto.nanopb_pb2 as nanopb_pb2 File "/home/vagrant/nanopb-0.4.2-linux-x86/generator/proto/nanopb_pb2.py", line 10, in from google.protobuf import symbol_database as _symbol_database ImportError: cannot import name 'symbol_database'
请告诉我我错过了什么。我应该只使用 Python2 吗?
另外不建议在 nanopb 中使用 protobuf 的哪些功能?nanopb 是否同时支持 proto2 和 proto3 语法?
解决方案
generator/proto/nanopb_pb2.py",第 10 行,从 google.protobuf 导入 symbol_database as _symbol_database ImportError: cannot import name 'symbol_database'
protoc
似乎版本和您的版本之间可能存在版本冲突python-protobuf
。尝试删除nanopb_pb2.py
,它应该会再次自动生成,可能会有更好的运气。
考虑到您使用的是二进制包,您也可以调用generator_bin/nanopb_generator
,它应该已经包含所有依赖项。
推荐阅读
- javascript - 数据未反映在 protip 中
- angular - 如何保持角度反应形式
- python - 如何让 OpenCV 保存分析视频的最后几秒
- c# - WinForms - 基于 ComboBox 选择动态创建文本框
- python - 根据索引计算numpy数组中所有点到单个点的距离
- java - 如何将接口加载为从黄瓜中的父模块自动装配的
- angular - 如何从角度对象数组中解析字符串?
- flutter - `pub get` 将 pubspec 依赖项下载到哪里?
- reactjs - React Native 矢量图标:为什么“back_arrow”无法渲染?
- recursion - ARM 汇编递归总和 1..n