Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"go get <package>" cannot find package

Tags:

go

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.

like image 503
andor kesselman Avatar asked Jun 27 '16 07:06

andor kesselman


People also ask

Where is package installed with go?

The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable.

How do I install go package dependencies?

To install dependencies, use the go get command, which will also update the go. mod file automatically. Since the package is not currently used anywhere in the project, it's marked as indirect. This comment may also appear on an indirect dependency package; that is, a dependency of another dependency.

How do I check my Gopath?

The GOPATH environment variable It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go ) on Windows. If you would like to work in a different location, you will need to set GOPATH to the path to that directory.


2 Answers

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.

like image 169
apxp Avatar answered Sep 29 '22 01:09

apxp


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.

like image 28
andor kesselman Avatar answered Sep 29 '22 01:09

andor kesselman