Sunday, 15 May 2011

python - Why do I see "cannot import name descriptor_pb2" error when using Google Protocol Buffers? -


We get this error when using the Python code generated from our Protobf classes:

   

The name descriptor_pb2 can not be imported

The equivalent C ++ generated code works fine, so it will appear that there is no problem with our actual proto definitions.

This error occurs when I try and import my class, like:

  import sys.path.append ('.. \ path \ To \ generate ') sys.path.append (' .. \ contrib \ Protobuf \ python ') FoBar_pb2 Import from FooBar  

Is it ideal to add system paths?

I have a protocol for protobuf \ python \ google \ descriptor_pb2.py but only descriptor.py - we get the latest Version, so I think we do not have any files.

Does anyone know what the solution is?

I believe that you generated with descript Or_pb2.py with Protocol yourself:

  generated by Protocol descriptor.pro-Python_out = GN /  

gn / A folder with python squares. After that, the following functions are correct:

  import from sys.path.append ('./.gen'). The file descriptor set should exist  

../gen / descriptor_pb2.py .


No comments:

Post a Comment