Cannot find package "golang.org/x/tools/cmd/goimports"

I have a weird problem in my system where Go can’t seem to find the “goimports” package even when I’m asking it to install the “goimports” package! Here’s how it goes:

$ go get -u golang.org/x/tools/cmd/goimports
package golang.org/x/tools/cmd/goimports: cannot find package "golang.org/x/tools/cmd/goimports" in any of:
	/usr/local/go/src/golang.org/x/tools/cmd/goimports (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/cmd/goimports (from $GOPATH)

This actually happened when trying out the Buffalo web framework, but I will ask separate questions if needed. Here’s my go env:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ankush/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build102401191=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

I’m going around in circles here. Please help! :slight_smile:

Exist an problem with your GOPATH, in your GOPATH “/home/ankush/go” have a folder with name “src” ?

Yup.

src$ pwd
/home/ankush/go/src
src$ ls
buffalo-projects  github.com  golang-book  golang.org  gopkg.in  sourcegraph.com

Try this:

cd /home/ankush/go/
export GOPATH=$( pwd )
export PATH=$PATH:$GOPATH/bin
go get -u golang.org/x/tools/cmd/goimports

I did that but it didn’t help. I don’t think it’s the problem with GOPATH. Here’s my go env output (from another terminal session):

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ankush/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build884564472=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Here’s my output:

$ go get -u golang.org/x/tools/...
package golang.org/x/tools/go/buildutil: cannot find package "golang.org/x/tools/go/buildutil" in any of:
	/usr/local/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/buildutil (from $GOPATH)
package golang.org/x/tools/go/callgraph: cannot find package "golang.org/x/tools/go/callgraph" in any of:
	/usr/local/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/callgraph (from $GOPATH)
package golang.org/x/tools/go/callgraph/cha: cannot find package "golang.org/x/tools/go/callgraph/cha" in any of:
	/usr/local/go/src/golang.org/x/tools/go/callgraph/cha (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/callgraph/cha (from $GOPATH)
package golang.org/x/tools/go/callgraph/rta: cannot find package "golang.org/x/tools/go/callgraph/rta" in any of:
	/usr/local/go/src/golang.org/x/tools/go/callgraph/rta (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/callgraph/rta (from $GOPATH)
package golang.org/x/tools/go/callgraph/static: cannot find package "golang.org/x/tools/go/callgraph/static" in any of:
	/usr/local/go/src/golang.org/x/tools/go/callgraph/static (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/callgraph/static (from $GOPATH)
package golang.org/x/tools/go/loader: cannot find package "golang.org/x/tools/go/loader" in any of:
	/usr/local/go/src/golang.org/x/tools/go/loader (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/loader (from $GOPATH)
package golang.org/x/tools/go/pointer: cannot find package "golang.org/x/tools/go/pointer" in any of:
	/usr/local/go/src/golang.org/x/tools/go/pointer (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/pointer (from $GOPATH)
package golang.org/x/tools/go/ssa: cannot find package "golang.org/x/tools/go/ssa" in any of:
	/usr/local/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/ssa (from $GOPATH)
package golang.org/x/tools/go/ssa/ssautil: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
	/usr/local/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
package golang.org/x/tools/godoc/analysis: cannot find package "golang.org/x/tools/godoc/analysis" in any of:
	/usr/local/go/src/golang.org/x/tools/godoc/analysis (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/godoc/analysis (from $GOPATH)
package golang.org/x/tools/godoc/util: cannot find package "golang.org/x/tools/godoc/util" in any of:
	/usr/local/go/src/golang.org/x/tools/godoc/util (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/godoc/util (from $GOPATH)
package golang.org/x/tools/godoc/vfs: cannot find package "golang.org/x/tools/godoc/vfs" in any of:
	/usr/local/go/src/golang.org/x/tools/godoc/vfs (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/godoc/vfs (from $GOPATH)

Looks like there were a lot of errors. Also, the original problem remains unresolved.

Is your GOPATH or any part of it symlinked to somewhere else?

The installation is correct, I installed in my environment, try install another package,

go get github.com/getsentry/raven-go

Nope. /home/ankush/go is a regular directory.

Yes, I was able to install it. Here’s what the directory looks like:

$ ls /home/ankush/go/src/github.com/getsentry/raven-go/
client.go           example/            .gitignore          LICENSE             .travis.yml
client_test.go      examples_test.go    .gitmodules         README.md           writer.go
Dockerfile.test     exception.go        http.go             runtests.sh         
.dockerignore       exception_test.go   http_test.go        stacktrace.go       
docs/               .git/               interfaces.go       stacktrace_test.go

Try again:

go get golang.org/x/tools/cmd/goimports

Same error again. :frowning_face:

$ go get golang.org/x/tools/cmd/goimports
package golang.org/x/tools/cmd/goimports: cannot find package "golang.org/x/tools/cmd/goimports" in any of:
	/usr/local/go/src/golang.org/x/tools/cmd/goimports (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/cmd/goimports (from $GOPATH)

You mean this?

$ ls -l /home/ankush/go/src 
total 24
drwxrwxr-x  3 ankush ankush 4096 Oct 25 23:05 buffalo-projects
drwxrwxr-x 41 ankush ankush 4096 Oct 25 23:36 github.com
drwxrwxr-x 12 ankush ankush 4096 Jul  8 22:07 golang-book
drwxrwxr-x  3 ankush ankush 4096 Jul  8 18:07 golang.org
drwxrwxr-x  4 ankush ankush 4096 Oct 25 10:56 gopkg.in
drwxrwxr-x  3 ankush ankush 4096 Jul  8 19:00 sourcegraph.com

and what would be the output of:

$> go get -u -v golang.org/x/tools/cmd/goimports

?

Here you go:

$ go get -u -v golang.org/x/tools/cmd/goimports
Fetching https://golang.org/x/tools/cmd/goimports?go-get=1
Parsing meta tags from https://golang.org/x/tools/cmd/goimports?go-get=1 (status code 200)
get "golang.org/x/tools/cmd/goimports": found meta tag get.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/cmd/goimports?go-get=1
get "golang.org/x/tools/cmd/goimports": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
package golang.org/x/tools/cmd/goimports: cannot find package "golang.org/x/tools/cmd/goimports" in any of:
	/usr/local/go/src/golang.org/x/tools/cmd/goimports (from $GOROOT)
	/home/ankush/go/src/golang.org/x/tools/cmd/goimports (from $GOPATH)

hum…
could you try removing by hand that directory?

$> rm -rf /home/ankush/go/src/golang.org/x/tools

and then re-go-get the package ?

2 Likes

Wooohooo! That worked! :smiley:

Now, the only question is, why? :slight_smile:

1 Like

it’s left as an exercize for the reader :slight_smile:
(I am guessing the tools repo hadn’t been really checked out with a proper go get nor a git clone (but perhaps just mkdir tools) preventing go get -u to properly update it later on.)

LOL!

Hmmm, that kinda makes sense. Thanks for all the help! :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.