【发布时间】:2021-09-22 16:37:47
【问题描述】:
复制: 在 MacOS Big Sur 上使用 Python3.9 创建了 Conda 环境,并为 Python 安装 gRPC:
conda create -n grpc python=3.9
conda activate grpc
pip3 install grpcio grpcio-tools
在这之后,我写了一个 proto 文件来定义一个服务。所以一个示例文件如下:
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;
}
当我尝试使用以下命令进行编译时:
python3 -m grpc_tools.protoc ./proto/service/service.proto --python_out=./proto/python --grpc_python_out=./proto/python
它给了我以下输出
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
为什么会发生这种情况,我该如何解决?关于为什么会发生这种情况的任何帮助都会非常有帮助。谢谢!
【问题讨论】:
标签: python python-3.x grpc grpc-python