1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Unable to generate code for proto files that use import

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have been using .proto files without any issue with C# and Java. I have more than hundred proto files spread across a folder hierarchy. I can compile in Visual Studio and in JetBrains IntelliJ Idea. Now I also want to compile in python. The files use a lot of import statements. There are no conflicts in this (no cyclic imports)...works fine in C# and Java. I'm not able to compile in python. My folder structure is simple:

    c:\\tmp\\proto


    Under this there are many folders containing proto files. I'm currently only using 'common' folder: c:\tmp\proto\common

    Following cmd line works fine:

    protoc --proto_path=c:/tmp/proto/common --python_out=c:/tmp/generated_python_files c:/tmp/proto/common\\app_codes.proto


    This file has no imports. I get the py file in the output folder. Following fails:

    protoc --proto_path=c:/tmp/proto/common --python_out=c:/tmp/generated_python_files c:/tmp/proto/common\\client_accounts.proto


    This file uses imports, as shown:

    import "google/protobuf/timestamp.proto";
    import "common/environment_params.proto";
    import "common/status_main.proto";
    import "common/aws_account.proto";
    import "common/azure_account.proto";
    import "common/google_account.proto";


    Result in cmd:

    C:\tmp\proto>protoc --proto_path=c:/tmp/proto/common/ --python_out=c:/tmp/generated_python_files client_accounts.proto

    common/environment_params.proto: File not found.
    common/status_main.proto: File not found.
    common/aws_account.proto: File not found.
    common/azure_account.proto: File not found.
    common/google_account.proto: File not found.
    c:/tmp/proto/common//client_accounts.proto:8:1: Import "common/environment_params.proto" was not found or had errors.
    c:/tmp/proto/common//client_accounts.proto:9:1: Import "common/status_main.proto" was not found or had errors.
    c:/tmp/proto/common//client_accounts.proto:10:1: Import "common/aws_account.proto" was not found or had errors.
    c:/tmp/proto/common//client_accounts.proto:11:1: Import "common/azure_account.proto" was not found or had errors.
    c:/tmp/proto/common//client_accounts.proto:12:1: Import "common/google_account.proto" was not found or had errors.
    c:/tmp/proto/common//client_accounts.proto:43:3: "EnvironmentParams" is not defined.
    c:/tmp/proto/common//client_accounts.proto:51:3: "Status" is not defined.
    c:/tmp/proto/common//client_accounts.proto:61:3: "EnvironmentParams" is not defined.
    c:/tmp/proto/common//client_accounts.proto:75:3: "EnvironmentParams" is not defined.
    c:/tmp/proto/common//client_accounts.proto:94:3: "AzureAccount" is not defined.
    c:/tmp/proto/common//client_accounts.proto:98:3: "AwsAccount" is not defined.
    c:/tmp/proto/common//client_accounts.proto:102:3: "GoogleAccount" is not defined.
    c:/tmp/proto/common//client_accounts.proto:27:60: "Status" is not defined.
    c:/tmp/proto/common//client_accounts.proto:30:64: "Status" is not defined.


    I have tried running the protoc command from various folders: c:/tmp or c:/tmp/proto or c:/tmp/proto/common. Same error. I have tried setting --proto_path to c:/tmp/proto and c:/tmp.

    I have also tried using the 'grpc compiler' extension in VS Code. It works for files without imports. Fails otherwise. Same error as above. I set the --proto_path in settings.json. Does not work.

    I believe somewhere path is not being passed properly. Issue is not in proto file imports - it compiles with c# and java.

    What could be the issue?

    regards Vinay

    Continue reading...

Compartilhe esta Página