编译协议缓冲区时,缺少输入或程序不可执行错误

when compile protocol buffer, missing input or program is not executable error

我正在尝试在 mac 上制作 golang+grpc 服务器。我按照这个例子安装了 golang、grpc、protocol buffer 并检查了 grpc 服务器 https://grpc.io/docs/quickstart/go/ 问题是当我尝试使用协议缓冲区编译 .proto 文件时,它说 'missing input' 或 'program is not executable'。

安装protocol buffer和grpc

brew install grpc protobuf

安装基于 golang 的协议插件

go get github.com/golang/protobuf/protoc-gen-go

协议路径

which protoc
/usr/local/bin/protoc

示例位置

/Users/usrname/go/src/google.golang.org/grpc/examples/helloworld

运行 原型编译器

protoc -I=/Users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/ --go_out=/Users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/ /Users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.proto

错误信息

protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.

这在 golang/protobuf issue 795

中提到过

See the Installation section of the page README:

Grab the code from the repository and install the proto package.
The simplest way is to run go get -u github.com/golang/protobuf/protoc-gen-go.

The compiler plugin, protoc-gen-go, will be installed in $GOPATH/bin unless $GOBIN is set. It must be in your $PATH for the protocol compiler, protoc, to find it.

因此请仔细检查 $GOPATH 的值(如果未设置,则默认为 ~/go

如果$GOPATH/bin(或~/go/bin)在你的$PATH?

OP camilla 确认不是:

$PATH also has :/Users/username/go/bin/protoc-gen-go

应该有:/Users/username/go/bin