问题描述
我正在使用 nanopb 库
I am using nanopb library
我寻求您的建议来解决构建问题 - 我正在使用 protobuf 3.12,nanopb 0.4.2, puython3,gcc .我编译了 c 和 python 的 protoc,但在构建时仍然遇到问题.
I seek your suggestion to resolve build issue - I am using protobuf 3.12,nanopb 0.4.2, puython3,gcc . I compiled protoc both c and python but still faced issue while building.
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 语法?
Please tell me what I am missing. Am I supposed to use Python2 only ?
Also what features of protobuf are not recommended to use in nanopb ? Does nanopb supports both proto2 and proto3 syntax ?
推荐答案
protoc
版本和您的 python-protobuf
版本之间似乎存在版本冲突.尝试删除 nanopb_pb2.py
,它应该会再次自动生成,可能运气更好.
It seems there may be a version conflict between protoc
version and your python-protobuf
version. Try to remove nanopb_pb2.py
, it should get autogenerated again possibly with better luck.
考虑到您使用的是二进制包,您还可以调用 generator_bin/nanopb_generator
,它应该已经包含了所有依赖项.
Considering you are using the binary package, you can also call generator_bin/nanopb_generator
, which should have all the dependencies already included.
这篇关于使用 nanopb 在 protobuf 中编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!