Skip to content

[BUG] python use python -m grpc_tools.proto gen code get ModuleNotFoundError: No module named 'buf' #147

Closed
@dobet

Description

@dobet

Description

one proto file gen go and python code. go run success, but python run get
ModuleNotFoundError: No module named 'buf'

Steps to Reproduce

  1. First step to reproduce the bug
    proto
syntax = "proto3";
  
package my.package;

import "google/protobuf/timestamp.proto";
import "buf/validate/validate.proto";

message Transaction {
  uint64 id = 1 [(buf.validate.field).uint64.gt = 999];
  google.protobuf.Timestamp purchase_date = 2;
  google.protobuf.Timestamp delivery_date = 3;

  string price = 4 [(buf.validate.field).cel = {
    id: "transaction.price",
    message: "price must be positive and include a valid currency symbol ($ or £)",
    expression: "(this.startswith('$') or this.startswith('£')) and float(this[1:]) > 0"
  }];

  option (buf.validate.message).cel = {
    id: "transaction.delivery_date",
    message: "delivery date must be after purchase date",
    expression: "this.delivery_date > this.purchase_date"
  };
}
  1. Second step to reproduce the bug

go use protoc to gen code and run sucess.

python use

python3 -m grpc_tools.protoc 

to gen code and run falied

  1. Third step to reproduce the bug
    ... additional steps as needed

Expected Behavior

python run success.

Actual Behavior

ModuleNotFoundError: No module named 'buf'

Screenshots/Logs

Environment

  • Operating System:
  • Version:
  • Compiler/Toolchain:
  • Protobuf Compiler & Version:
  • Protoc-gen-validate Version:
  • Protovalidate Version:

Possible Solution

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions