简体   繁体   中英

“go get <package>” cannot find package

The command go get github.com/gogo/protobuf/proto doesn't seem to be working despite GOPATH set.

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:

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.

The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.

go get supports also build flags to rebuild the package you could try -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. 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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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