0

I am using nanopb library

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'

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 ?

Dhiman
  • 59
  • 6

1 Answers1

0

generator/proto/nanopb_pb2.py", line 10, in from google.protobuf import symbol_database as _symbol_database ImportError: cannot import name 'symbol_database'

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.

Considering you are using the binary package, you can also call generator_bin/nanopb_generator, which should have all the dependencies already included.

jpa
  • 10,351
  • 1
  • 28
  • 45
  • It worked by removing nanopb_pb2.py ! thanks. I saw in issue list that nanopb 0.4.2 is using python3 by default. Also I saw that proto3 is supported. Any idea which proto3 features to be avoided in nanopb ? – Dhiman Aug 24 '20 at 15:10
  • @Dhiman I'm not aware of a reason to avoid any particular feature. Some features (such as `Any` message type and deeply nested messages) can add complexity, but that applies to all protobuf libraries. – jpa Aug 24 '20 at 18:33
  • Thanks for help. Perhaps I am missing something more. In Linux make is building the pb.c and pb.h files. However when I run python3 ../../generator/nanopb_generator.py simple.pb or ../../generator-bin/nanopb_generator simple.pb it is giving error. Need to check nanopb.mk in extra folder that works in make.. – Dhiman Aug 28 '20 at 08:58