运行”go generate”命令时出现“protoc”:在$PATH中找不到可执行文件的错误。

huangapple go评论87阅读模式
英文:

Getting "protoc": executable file not found in $PATH when running "go generate" command

问题

我们有一个用Go语言编写的应用程序,我们正在使用GRPC来定义服务契约。

当我们尝试运行"go generate"命令从proto文件生成存根时,会出现以下错误:

main.go:4: 运行"protoc"时:exec: "protoc": 在$PATH中找不到可执行文件

代码中的命令格式:

//go:generate protoc -I . --go-grpc_out=. --go_out=.  ./proto/service.proto

注意:

  • 我已经安装了protoc-gen-goprotoc-gen-go-grpc
  • 尝试搜索上述错误,但还没有找到解决方案。
英文:

We have an application written in GoLang and we are using GRPC for defining service contracts.

When we try to run "go generate" command to generate stub from proto file it gives following error:

main.go:4: running "protoc": exec: "protoc": executable file not found in $PATH

Command format in code:

//go:generate protoc -I . --go-grpc_out=. --go_out=.  ./proto/service.proto

Note:

  • I have already installed protoc-gen-go and protoc-gen-go-grpc
  • Tried to search for the above error but haven't been able to find a solution yet.

答案1

得分: 3

protoc-gen-goprotoc-gen-go-grpcprotoc的插件。您需要安装protoc(Protobuf编译器)本身,如Go gRPC - 先决条件中所述。

请访问protobuf - 发布页面进行下载。

在Mac上,您可以使用brew install protobuf进行安装。

英文:

protoc-gen-go and protoc-gen-go-grpc are plugins for protoc. You need to install the protoc (the Protobuf compiler) itself, as explained in Go gRPC - Prerequisites.

See protobuf - Releases page for a download.

On a Mac can just use brew install protobuf.

答案2

得分: 0

为您安装protobuf编译器工具:

yum install protobuf-compiler
英文:

Installing protobuf-complier woker for me.

yum install protobuf-compiler

huangapple
  • 本文由 发表于 2022年2月1日 13:31:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/70935945.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定