mac上生成go文件失败报错,gRpc-- protoc-gen-go: program not found or is not executable

根据proto文件生成对应的go文件

搭建grpc环境

brew tap grpc/grpc
brew install protobuf
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go

生成go文件命令

protoc --go_out=plugins=grpc:. *.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.

  • 解决方案
    找到protoc-gen-go 文件,执行以下命令,该文件通过go get安装时会安装在$GOPATH/go/bin目录下
    cp protoc-gen-go /usr/local/bin/
    然后vim ~/.bash_profile
    export GOPATH=$HOME/go PATH=$PATH:$GOPATH/bin

之后source ~/.bash_profile即可

原文地址:https://www.cnblogs.com/codeBang/p/13324122.html