【问题标题】:Compiling gRPC protobuf - "program not found or is not executable"编译 gRPC protobuf - “程序未找到或不可执行”
【发布时间】:2020-10-19 19:29:02
【问题描述】:

我正在努力编译我的 .proto 文件以在 Python 中生成 gRPC 存根。

我当前的工作目录是 ./predictor。我在 ./proto 文件夹中有一个simulator.proto 文件。

我正在处理的项目的自述文件说我应该运行

protoc -I ../proto/ --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../proto/simulator.proto

这失败并给了我

: program not found or is not executable
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.

我用python -m grpc_tools.protoc ... 试了一下,还是不行。 我已经仔细检查了我是否安装了 grpc,我已经用 pip 重新安装了它,并且 git clone 了 grpc 文件夹并从源代码构建。我不知道还能做什么。有人有想法吗?

【问题讨论】:

    标签: grpc grpc-python


    【解决方案1】:

    您不能(很容易!?)将protoc 用于 Python,最好使用您描述的模块。

    命令应该类似于:

    python \
    -m grpc_tools.protoc \
    --proto_path=../proto \
    --python_out=. \
    --grpc_python_out=. \
    ../proto/*.proto
    

    假设您有一个名为 proto 的父目录,其中至少包含一个 .proto 文件,并且您从 python 运行此命令:

    .
    ├── protos
    │   └── x.proto
    └── python
        ├── x_pb2_grpc.py
        └── x_pb2.py
    

    你在使用模块时遇到什么错误?

    【讨论】:

    • 我收到RuntimeWarning: 'grpc_tools.protoc' found in sys.modules after import of package 'grpc_tools', but prior to execution of 'grpc_tools.protoc'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) Missing output directives.。我不认为警告很重要,但我认为缺少输出指令是个问题。
    • 运行您发送的命令会生成simulator_pb2.py文件,但不会生成simulator_pb2_grpc.py
    • 其实我想我现在明白了。我错过了一个 cli 标志选项。感谢您的帮助!
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 2020-01-02
    • 2022-07-07
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多