Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

Error while generating grpc code in python, unable to import *_pb.py file into *_pb_grpc.py

I have the following project structure:

|-definitions
|--dummy_grpc
|----dummy_grpc.proto
|-python_client

What I'm trying to do is generating the dummy_grpc.proto inside the python_client folder and then use the library(? probably is not even the correct word to describe a package) in other project by importing from github.
So in root of the project I have created a simple script to generate the code:

"""Runs protoc with the gRPC plugin to generate messages and gRPC stubs."""

from grpc_tools import protoc

protoc.main((
    '',
    '-Idefinitions/dummy_grpc/',
    '--python_out=python_client',
    '--grpc_python_out=python_client',
    'definitions/dummy_grpc/dummy_grpc.proto',
))

The script run and it creates two files inside python_client folder: dummy_grpc_pb2_grpc.py and dummy_grpc_pb2.py. The first file import the second file but, for some reason is not to import the file (error is ```Unable to import file), the import looks like:

import dummy_grpc_pb2 as dummy__grpc__pb2

I was thinking that maybe python is not able to see the file so I created a init.py inside python_client folder but with no luck. Any suggestion?

question from:https://stackoverflow.com/questions/65891029/error-while-generating-grpc-code-in-python-unable-to-import-pb-py-file-into

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...