【问题标题】:Proto compiler fails on MacOS Big Sur原型编译器在 MacOS Big Sur 上失败
【发布时间】: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


    【解决方案1】:

    如果您使用的是 M1,我建议您阅读此评论以了解如何使用我们的预编译轮:https://github.com/grpc/grpc/issues/25082#issuecomment-754718296。

    如果没有,您可能会混合使用 macOS 拥有的 Python3.9 和 Conda 拥有的 Python 二进制文件。

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 2022-01-14
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多