无法构建Protobuf到Go端点。

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

Unable to build protobuf to go endpoint

问题

使用protobuf版本2.6.1(我通过Homebrew安装的)。

我正在尝试运行以下命令:

$ protoc --go_out=../cloud/ *.proto

但是我一直收到以下错误信息:

$ protoc-gen-go: 找不到程序或不可执行
$ --go_out: protoc-gen-go: 插件返回状态码1,失败。

我已经在我的go路径中安装了protoc-gen-go。还有其他人遇到这个问题吗?

英文:

using protobuf version 2.6.1 ( which i installed via homebrew)

I am trying to run

$ protoc --go_out=../cloud/ *.proto

I keep receiving this error.

$ protoc-gen-go: program not found or is not executable
$ --go_out: protoc-gen-go: Plugin failed with status code 1.

I have the protoc-gen-go installed in my go path.
Anyone else have this issue?

答案1

得分: 61

protoc-gen-go 需要在你的 shell 路径中,即在 PATH 环境变量所列出的目录之一,这与 Go 路径不同。你可以通过在命令行中输入 protoc-gen-go 进行测试:如果显示“command not found”(或类似的消息),那么它就不在你的 PATH 中。

英文:

protoc-gen-go needs to be in your shell path, i.e. one of the directories listed in the PATH environment variable, which is different from the Go path. You can test this by simply typing protoc-gen-go at the command line: If it says "command not found" (or similar) then it's not in your PATH.

答案2

得分: 31

使用

$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

比使用

$ sudo apt-get install golang-goprotobuf-dev

更安全,因为最新的 protoc-gen-go 使用了库 github.com/golang/protobuf/proto,而 apt-get 中的 protoc-gen-go 使用了库 code.google.com/p/goprotobuf/proto,该库现在已经不存在。

英文:

Using

$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

is more safe than using

$ sudo apt-get install golang-goprotobuf-dev

Because the latest protoc-gen-go is using the lib github.com/golang/protobuf/proto, but protoc-gen-go in apt-get using the lib code.google.com/p/goprotobuf/proto which didn't exist now.

答案3

得分: 31

你应该正确定义你的GO_PATH,即你的Go包所在的位置。换句话说,GO_PATH就是你的Go工作区。GO_PATH应该是~/go

protoc-gen-go应该在你的PATH中。在安装后,protoc-gen-go位于$GO_PATH/bin中。

将以下两行重要的代码添加到你的~/.bash_profile文件中:

export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin

然后你需要启动一个新的shell会话,或者只需输入以下命令:

$ source ~/.bash_profile

英文:
  1. You should properly define your GO_PATH - where your go packages
    live.
    In other words, GO_PATH is your go workspace. The GO_PATH
    should be ~/go.

  2. protoc-gen-go should be in your PATH. While protoc-gen-go lives in $GO_PATH/bin after you installed it.


Add these 2 important lines to your ~/.bash_profile:

export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin

Then you need to start a new shell session or just type in this line:

$ source ~/.bash_profile

答案4

得分: 13

在Ubuntu 18.04上,已经验证过以下命令可以解决这个问题:

sudo apt-get install golang-goprotobuf-dev

英文:

On Ubuntu 18.04, this is verified working to solve this issue:

sudo apt-get install golang-goprotobuf-dev

答案5

得分: 6

我有Ubuntu 18.04.02 LTS,并使用以下命令安装了protoc

sudo apt install protobuf-compiler

我已经正确设置了我的GOPATH和GOBIN,但是当我运行以下命令时:

protoc --go_out=. <filename>

我遇到了以下错误:

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

在阅读了一些资料后,我发现运行以下命令可以解决这个问题:

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

希望这对其他人有所帮助。

英文:

I have Ubuntu 18.04.02 LTS and installed protoc using

sudo apt install protobuf-compiler

I have my GOPATH and GOBIN set correctly, but still when I did a
protoc --go_out=. &lt;filename&gt;
I was getting

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

After reading bunch of places, was able to find that doing

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

was able to fix the issue.
Hope this helps someone out there.

答案6

得分: 4

我是你的中文翻译助手,以下是翻译好的内容:

我是如何解决的:

  1. 运行以下命令将$GOPATH/bin添加到PATH中:
    export PATH=$PATH:$GOPATH/bin
  2. .bash_profile文件中,在export PATH=$PATH:$GOPATH/bin行之前添加export GOPATH=$(go env GOPATH)
  3. 再次运行go get -u来获取所需的包。
  4. 在你的情况下,运行代码protoc --go_out=../cloud/ *.proto
英文:

How I solved:

  1. Add $GOPATH/bin to PATH by running
    export PATH=$PATH:$GOPATH/bin
  2. add export GOPATH=$(go env GOPATH) above export PATH=$PATH:$GOPATH/bin line inside the .bash_profile file.
  3. run go get -u for the required packages again.
  4. run the code protoc --go_out=../cloud/ *.proto in your case.

答案7

得分: 3

我遇到了同样的问题。

$ protoc --go_out=plugins=grpc:pb/ *.proto
protoc-gen-go: 找不到程序或不可执行
--go_out: protoc-gen-go: 插件返回状态码 1。

解决方案如下:

找到 protoc-gen-go 的安装目录,确保它在你的 $PATH 中。

export PATH=$PATH:/path/to/dir

最好将其添加到你的 .bash_profile 中。

echo $"export PATH=$PATH:$(/path/to/dir)" >> ~/.bash_profile
source ~/.bash_profile

然后一切都会正常的。

英文:

I met the same problem.

$ protoc --go_out=plugins=grpc:pb/ *.proto
protoc-gen-go: program not found or is not executable
--go_out: protoc-gen-go: Plugin failed with status code 1.

The solution as below:

Find the installation directory of protoc-gen-go, it must be in your $PATH.

export PATH=$PATH:/path/to/dir

You'd better add it to your .bash_profile

echo $&quot;export PATH=$PATH:$(/path/to/dir)&quot; &gt;&gt; ~/.bash_profile
source ~/.bash_profile

then everything is ok.

答案8

得分: 3

我解决这个问题的方法是:

将 go 工作空间中的 protoc-gen-go 复制到 /usr/local/bin/ 文件夹中。

然后按照之前的方式运行你的命令,例如 "protoc --go_out=../cloud/ *.proto"。

英文:

What I did to solve this was:

copy protoc-gen-go from the go bin folder in go workspace to /usr/local/bin/

run your command as before in your case "protoc --go_out=../cloud/ *.proto"

答案9

得分: 3

直接从grpc文档中:

用于Go的协议编译器的插件:

使用以下命令安装Go的协议编译器插件:

$ export GO111MODULE=on  # 启用模块模式
$ go get google.golang.org/protobuf/cmd/protoc-gen-go \
         google.golang.org/grpc/cmd/protoc-gen-go-grpc

更新您的PATH,以便protoc编译器可以找到这些插件:

$ export PATH="$PATH:$(go env GOPATH)/bin"
英文:

Directly from grpc documentation:

Go plugins for the protocol compiler:

Install the protocol compiler plugins for Go using the following commands:

$ export GO111MODULE=on  # Enable module mode
$ go get google.golang.org/protobuf/cmd/protoc-gen-go \
         google.golang.org/grpc/cmd/protoc-gen-go-grpc

Update your PATH so that the protoc compiler can find the plugins:

$ export PATH=&quot;$PATH:$(go env GOPATH)/bin&quot;

答案10

得分: 2

Mby会帮助某些人。我正在使用Fedora 29。

当我安装Go语言时,我执行了以下操作:

echo 'export GOPATH=$HOME/Go' >> $HOME/.bashrc
source $HOME/.bashrc

这样我就设置好了GOPATH。
接下来我执行:

echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc

然后我的protoc编译器就能正常工作了。

英文:

Mby will help for somebody. I'm on Fedora 29.

When I installed Go I did:

echo &#39;export GOPATH=$HOME/Go&#39; &gt;&gt; $HOME/.bashrc
source $HOME/.bashrc

So I have my GOPATH set up.
Next I do:

echo &#39;export PATH=$PATH:$GOPATH/bin&#39; &gt;&gt; $HOME/.bashrc
source $HOME/.bashrc

And my protoc compiler work lika a charm.

答案11

得分: 1

在 macOS 上,我只安装了 protoc,使用 brew install protobuf 命令进行安装。

因此,为了获取 Go 代码生成器,我还需要执行 brew install protoc-gen-go 命令。

英文:

On macOS, I had installed just protoc with brew install protobuf.

So, to get the go code generator, I also needed to do brew install protoc-gen-go.

答案12

得分: 0

如果你正在使用Fedora,请确保安装了"protoc-gen-go"软件包,并且它的二进制文件在你的shell PATH中。

$sudo dnf install protoc-gen-go -y

英文:

If you're using Fedora, ensure that the package "protoc-gen-go" is installed, and it's binary is in your shel PATH.

$sudo dnf install protoc-gen-go -y

答案13

得分: 0

如果你在运行proto时在控制台上收到错误消息,导致你找到了这个页面:

Protoc命令未找到

如果你使用的是Linux系统,请按照以下步骤操作:

  1. 在这里下载protoc文件:
    https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.4
    (在我的情况下,我下载了protoc-3.19.4-linux-x86_64.zip文件)
  2. 将文件解压到/home/your_username/.local文件夹中
  3. 然后你会在这个位置找到它:/home/your_username/.local/bin/protoc
  4. 完成。现在你可以在终端中输入"protoc"来使用它。
英文:

If found this page because you get the error message in console when you run proto:

Protoc command not found

If you use linux then follow the instructions below:

  1. download the protoc file here
    https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.4
    (i used to download the protoc-3.19.4-linux-x86_64.zip in my case.
  2. extract the files in this folder `/home/your_username/.local
  3. then you will have it like this: /home/your_username/.local/bin/protoc
  4. Profit. this will work by typing just "protoc" in your terminal

答案14

得分: 0

我已经安装了 protoc 3.20.0。
但是我没有找到用于生成 Golang 代码的标签。
我已经贴出了所有可用标签的截图。

英文:

enter image description here

I have installed protoc 3.20.0.
But I didn't get the tag for generating the code for Golang.
I have pasted the screenshot of all available tags.

答案15

得分: -1

请确保您的PATH变量中指向proton-gen-go的路径是绝对路径(例如/Users/me/go/bin而不是~/go/bin)。

显然,protoc不知道如何展开~

英文:

Ensure that your path to proton-gen-go in your PATH variable is absolute (i.e. /Users/me/go/bin instead of ~/go/bin.

Apparently protoc does not know how to expand ~.

huangapple
  • 本文由 发表于 2015年1月23日 05:27:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/28099004.html
匿名

发表评论

匿名网友

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

确定