To replicate: Created a Conda environment with Python3.9 on MacOS Big Sur and install gRPC for Python:
conda create -n grpc python=3.9
conda activate grpc
pip3 install grpcio grpcio-tools
After this, I wrote a proto file to define a service. So a sample file like:
package unary;
service Unary{
// A simple RPC.
//
// Obtains the MessageResponse at a given position.
rpc GetServerResponse(Message) returns (MessageResponse) {}
}
message Message{
string message = 1;
}
message MessageResponse{
string message = 1;
bool received = 2;
}
and when I tried compiling with the following command:
python3 -m grpc_tools.protoc ./proto/service/service.proto --python_out=./proto/python --grpc_python_out=./proto/python
it gave me the following output
Traceback (most recent call last):
File "/opt/homebrew/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/homebrew/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/opt/homebrew/lib/python3.9/site-packages/grpc_tools/protoc.py", line 22, in <module>
from grpc_tools import _protoc_compiler
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/grpc_tools/_protoc_compiler.cpython-39-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/lib/python3.9/site-packages/grpc_tools/_protoc_compiler.cpython-39-darwin.so: mach-o, but wrong architecture
/opt/homebrew/lib/python3.9/site-packages/grpc_tools/_protoc_compiler.cpython-39-darwin.so: mach-o, but wrong architecture
Why is this happening, and how can I fix it? Any help regarding why this is happening would be very helpful. Thank you!