简体   繁体   English

“去拿<package> ” 找不到包

[英]“go get <package>” cannot find package

The command go get github.com/gogo/protobuf/proto doesn't seem to be working despite GOPATH set.尽管设置了go get github.com/gogo/protobuf/proto但命令go get github.com/gogo/protobuf/proto似乎GOPATH

GOPATH="/Users/tmp/Documents/workspace/app/go"

I see a similar problem with other packages.我看到其他软件包也有类似的问题。

Error being read:读取错误:

package github.com/gogo/protobuf/proto: cannot find package "github.com/gogo/protobuf/proto" in any of:
    /usr/local/go/src/github.com/gogo/protobuf/proto (from $GOROOT)
    /Users/tmp/Documents/workspace/app/go/src/github.com/gogo/protobuf/proto (from $GOPATH)

Running go env shows:运行go env显示:

GOARCH="amd64"
GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin"
GOPATH="/Users/tmp/Documents/workspace/app/go" GORACE=""
GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What is the problem and how do I fix this?有什么问题,我该如何解决? I haven't found anything on this online but this was working prior.我在网上没有找到任何东西,但这之前是有效的。

I don't know if it is neccesery to delete the entire folder.我不知道是否需要删除整个文件夹。

First you could try to use the -u flag ( go cmd doc ) to reinstall all the other dependencies.首先,您可以尝试使用-u标志( go cmd doc )重新安装所有其他依赖项。

The -u flag instructs get to use the network to update the named packages and their dependencies. -u 标志指示 get 使用网络来更新命名包及其依赖项。 By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.默认情况下,get 使用网络来检查丢失的包,但不使用它来查找现有包的更新。

go get supports also build flags to rebuild the package you could try -a : go get 支持也构建标志来重建你可以尝试的包-a

-a force rebuilding of packages that are already up-to-date. - 强制重建已经是最新的软件包。

After some fiddling, I found out that somehow source files within the src directory got deleted.经过一番摆弄,我发现 src 目录中的源文件不知何故被删除了。 I removed the entire folder and its contents, which caused the entire package to be reinstalled.我删除了整个文件夹及其内容,这导致整个包被重新安装。 This seems to have cleared the issue and resolved it.这似乎已经清除了问题并解决了它。

I should note I ran into another error along the way of debugging:我应该注意到我在调试过程中遇到了另一个错误:

no buildable Go source files in /Users/tmp/Documents/workspace/app/go/src/github.com/golang/protobuf/proto /Users/tmp/Documents/workspace/app/go/src/github.com/golang/protobuf/proto 中没有可构建的 Go 源文件

Again, this was all resolved after deleting the entire package in the source folder.同样,在删除源文件夹中的整个包后,这一切都得到了解决。

@Mark: One thing to note is that I was referencing the correct package name according to https://github.com/golang/protobuf . @Mark:要注意的一件事是,我根据https://github.com/golang/protobuf引用了正确的包名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM