“unrecognized import path” with go get

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

I'm trying to install a web.go, but running go get github.com/hoisie/web returns

package bufio: unrecognized import path "bufio" package bytes: unrecognized import path "bytes" package crypto/rand: unrecognized import path "crypto/rand" package crypto/sha1: unrecognized import path "crypto/sha1" package crypto/tls: unrecognized import path "crypto/tls" package encoding/base64: unrecognized import path "encoding/base64" package encoding/binary: unrecognized import path "encoding/binary" package encoding/json: unrecognized import path "encoding/json" package errors: unrecognized import path "errors" package fmt: unrecognized import path "fmt" 

and this continues for a while with various packages, before returning nothing else. go env gives me:

GOARCH="amd64" GOBIN="/usr/local/go/bin" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="" GORACE="" GOROOT="/home/me/go" GOTOOLDIR="/home/me/go/pkg/tool/linux_amd64" TERM="dumb" CC="gcc" GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread" CXX="g++" CGO_ENABLED="1" 

How can I install web.go? Using go get (rather than go install) is what is in the README on the github page. My Go version is go version go1.2 linux/amd64.

回答1:

The issues are relating to an invalid GOROOT.

I think you installed Go in /usr/local/go.
So change your GOROOT path to the value of /usr/local/go/bin.

It seems that you meant to have your workspace (GOPATH) located at /home/me/go.

This might fix your problem.
Add this to the bottom of your bash profile, located here => $HOME/.profile

export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin 

Make sure to remove the old references of GOROOT.

Then try installing web.go again.

If that doesn't work, then have Ubuntu install Go for you.

sudo apt-get install golang

Video tutorial: http://www.youtube.com/watch?v=2PATwIfO5ag



回答2:

I had exactly the same issue, after moving from old go version (installed from old PPA) to newer (1.2.1) default packages in ubuntu 14.04.

The first step was to purge existing go:

sudo apt-get purge golang* 

Which outputs following warnings:

dpkg: warning: while removing golang-go, directory '/usr/lib/go/src' not empty so not removed dpkg: warning: while removing golang-go.tools, directory '/usr/lib/go' not empty so not removed 

It looks like removing go leaves some files behind, which in turn can confuse newer install. More precisely, installation itself will complete fine, but afterwards any go command, like "go get something" gives those "unrecognized import path" errors.

All I had to do was to remove those dirs first, reinstall golang, and all works like a charm (assuming you also set GOPATH)

# careful! sudo rm -rf /usr/lib/go /usr/lib/go/src sudo apt-get install golang-go golang-go.tools 


回答3:

I installed Go with brew on OSX 10.11, and found I had to set GOROOT to:

/usr/local/Cellar/go/1.5.1/libexec

(Of course replace the version in this path with go version you have)

Brew uses symlinks, which were fooling the gotool. So follow the links home.



回答4:

Because GFW forbidden you to access golang.org ! And when i use the proxy , it can work well.

you can look at the information using command go get -v -u golang.org/x/oauth2



回答5:

I had the same problem on MacOS 10.10. And I found that the problem caused by OhMyZsh shell. Then I switched back to bash everything went ok.

Here is my go env

bash-3.2$ go env GOARCH="amd64" GOBIN="" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/bis/go" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common" CXX="clang++" CGO_ENABLED="1 


回答6:

I had the same issue after having upgraded go1.2 to go1.4.

I renamed src to _src in my GOPATH then did a go get -v

It worked then I deleted _src.

Hope it helps.



回答7:

I had a similar problem. But that was just because the package I was installing is not in the $GOPATH/src/ directory, when I installed in that directory everything worked fine (except the package name is different caused problem, but I used Makefile to build so that may not be relevant to your problem).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!