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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…