I have to write a RPC service for some Python apps. I have an IDL file called solver.proto
and generated some code from it using the grpcio-tools
module. Here is the resulting project structure:
solver-service
├── main.py
└── protos/
├── __init__.py
├── __pycache__
│ └── ...
├── generate_pb.py
├── solver.proto
├── solver_pb2.py
└── solver_pb2_grpc.py
I have my PYTHONPATH set to /abs/path/to/solver-service
and I try to import my auto-generated gRPC classes from this directory but hit the following:
solver-service$ python3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import protos.solver_pb2
>>> import protos.solver_pb2_grpc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/abs/path/to/solver-service/protos/solver_pb2_grpc.py", line 4, in <module>
import solver_pb2 as solver__pb2
ImportError: No module named 'solver_pb2'
So for whatever reason I can import protos.solver_pb2
successfully but the interpreter complains about importing protos.solver_pb2_grpc
due to some relative path issue. Calling all Python devs doing gRPC work out there -- how do I get this working?