Protobuf: The generated import code in Python have error in xxx_pb2_grpc.py

Created on 24 Apr 2018  路  5Comments  路  Source: protocolbuffers/protobuf

The protoc generate xxx_pb2_grpc.py code like this for example:

# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc
import shadowfax_pb2 as shadowfax__pb2

However, in some case, line 3 will fail with an Error:

ModuleNotFoundError: No module named 'shadowfax_pb2'

How about changing this line to:

from . import shadowfax_pb2 as shadowfax__pb2
invalid

Most helpful comment

Here is my workaround in macOS

cd py_protos && sed -i '' 's/^\(import.*pb2\)/from . \1/g' *.py

All 5 comments

Here is my workaround in macOS

cd py_protos && sed -i '' 's/^\(import.*pb2\)/from . \1/g' *.py

@nathanielmanistaatgoogle, can you help to take a look?

I suspect that this is the same problem that we're tracking in gRPC Python issue 11041 and gRPC Python issue 9450.

I am closing this issue as duplicated with some issues under gRPC

See https://github.com/protocolbuffers/protobuf/issues/1491 for a discussion of this issue.

Was this page helpful?
0 / 5 - 0 ratings