ModuleNotFound issues with Protobuf / Python

Skip to first unread message

Ryan Truran

Dec 23, 2022, 1:19:00 AM12/23/22
to Protocol Buffers
I have many module not found errors in my generated code. 

here is the proto for my wrapper message. 

syntax = "proto3";

import "internal_messages/async.proto";
import "external_messages/async.proto";
import "internal_messages/request.proto";
import "external_messages/request.proto";

package api;

message ApiMessage {
uint32 protocol_version = 1;
uint32 sequence_id = 2;
uint32 timestamp = 3;

oneof api_message_type {
Request request = 13;
Async async = 15;

message Async {
oneof message {
InternalAsync internal_async = 0x1001;
ExternalAsync external_async = 0x1002;

message Request {
oneof message {
InternalRequest internal_request = 0x1001;
ExternalRequest external_request = 0x1002;

I'm compiling with the following command.

protoc --python_out=:classes/python **/*.proto

When I import the generated class, the other imports fail, with a ModuleNotFound Error, unless I modify the generated code to make the imports relative. 

Obviously, updating the generated code is not ideal for many reasons, so I'm curious if there is a better way to do this. 


Deanna Garcia

Dec 27, 2022, 3:43:54 PM12/27/22
to Protocol Buffers
Instead of modifying the imports in the generated code, can you modify the imports in the proto definition?  It seems like the most likely cause of this error is that the import paths are incorrect.
Reply all
Reply to author
0 new messages