Failing to Import Files Compiled from Protobuf in Python

2,758 views
Skip to first unread message

Charlie Tian

unread,
Sep 15, 2023, 12:31:25 AM9/15/23
to Protocol Buffers
My directory structure is as follows:

     |-test.py
     |-test.proto
     |-test_pb2.py
     |-__init__.py
     |-comm
        |-comm.proto
        |-comm_pb2.py
        |-__init__.py  

both \_\_init__.py is empty
and **test.proto** is like this:

    package test;
    import "comm/comm.proto";

    message Test{
    optional comm.Foo foo = 1;
    }
and **comm.proto** is like this:

    package comm;

    message Foo{}

i successfuly used command *protoc --python_out=. -I.* to compile **comm.proto** and **test.proto**
but when i tried to import ***test_pb2*** in ***test.py***, i encounter this error

    TypeError: Couldn't build proto file into descriptor pool: Depends on file 'comm/comm.proto', but it has not been loaded


Can someone help me identify the reason and provide a solution, please?

Daz Wilkin

unread,
Sep 17, 2023, 9:04:13 PM9/17/23
to Protocol Buffers
I took a stab at answering your question on Stack overflow:

Reply all
Reply to author
Forward
0 new messages