Why do I see “cannot import name descriptor_pb2” error when using Google Protocol Buffers?

前端 未结 5 715
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 03:51

When using the generated Python code from our protobuf classes, we get this error:

cannot import name descriptor_pb2

The equivalent C++ gen

5条回答
  •  耶瑟儿~
    2021-01-18 03:59

    python setup.py build

    This step is mandatory as it generated some of the source files.

    Generating google/protobuf/descriptor_pb2.py... Generating google/protobuf/compiler/plugin_pb2.py... Generating google/protobuf/unittest_pb2.py... Generating google/protobuf/unittest_custom_options_pb2.py... Generating google/protobuf/unittest_import_pb2.py... Generating google/protobuf/unittest_import_public_pb2.py... Generating google/protobuf/unittest_mset_pb2.py... Generating google/protobuf/unittest_no_generic_services_pb2.py... Generating google/protobuf/internal/descriptor_pool_test1_pb2.py... Generating google/protobuf/internal/descriptor_pool_test2_pb2.py... Generating google/protobuf/internal/test_bad_identifiers_pb2.py... Generating google/protobuf/internal/missing_enum_values_pb2.py... Generating google/protobuf/internal/more_extensions_pb2.py... Generating google/protobuf/internal/more_extensions_dynamic_pb2.py... Generating google/protobuf/internal/more_messages_pb2.py... Generating google/protobuf/internal/factory_test1_pb2.py... Generating google/protobuf/internal/factory_test2_pb2.py... Generating google/protobuf/pyext/python_pb2.py... bla...

    Precisely the 'descriptor_pb2.py'

提交回复
热议问题