英文:
"unrecognized import path" with go get
问题
我正在尝试安装web.go
,但运行go get github.com/hoisie/web
返回以下错误信息:
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"
在返回这些错误信息之前,还会继续列出其他一些包的错误。运行go env
命令可以得到以下输出:
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"
请问我该如何安装web.go
?README文件中提到要使用go get
命令(而不是go install
)。我的Go版本是go version go1.2 linux/amd64
。
英文:
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
得分: 110
问题与无效的GOROOT
相关。
我认为你将Go安装在了/usr/local/go
目录下。所以将你的GOROOT
路径更改为/usr/local/go/bin
的值。
看起来你的工作空间(GOPATH)应该位于/home/me/go
。
这可能会解决你的问题。将以下内容添加到你的bash配置文件的末尾,位置在$HOME/.profile
:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin
确保删除旧的GOROOT
引用。
然后尝试重新安装web.go。
如果这样还不起作用,那么请让Ubuntu为你安装Go。
sudo apt-get install golang
视频教程:
http://www.youtube.com/watch?v=2PATwIfO5ag
英文:
The issues are relating to an invalid GOROOT
.
I think you installed Go in /usr/local/go
.<br>
So change your GOROOT
path to the value of /usr/local/go/bin
.<br>
It seems that you meant to have your workspace (GOPATH) located at /home/me/go
.
This might fix your problem.<br>
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
得分: 39
我在OSX 10.11上使用brew
安装了Go,并发现我需要设置GOROOT
为:
/usr/local/Cellar/go/1.5.1/libexec
(当然,将此路径中的版本替换为您所拥有的Go版本)
Brew使用符号链接,这会让gotool产生困惑。所以请按照链接的路径进行设置。
英文:
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.
答案3
得分: 23
我遇到了完全相同的问题,从旧的go版本(从旧的PPA安装)迁移到新的(1.2.1)默认包在ubuntu 14.04中。
第一步是清除现有的go:
sudo apt-get purge golang*
这会输出以下警告:
dpkg: 警告: 删除 golang-go 时,目录 '/usr/lib/go/src' 不为空,因此未删除
dpkg: 警告: 删除 golang-go.tools 时,目录 '/usr/lib/go' 不为空,因此未删除
看起来删除go会留下一些文件,这反过来可能会混淆新的安装。更准确地说,安装本身会顺利完成,但之后任何go命令,比如"go get something"都会出现"无法识别的导入路径"错误。
我所需要做的就是先删除这些目录,然后重新安装golang,一切都正常工作(假设您也设置了GOPATH)
# 小心!
sudo rm -rf /usr/lib/go /usr/lib/go/src
sudo apt-get install golang-go golang-go.tools
英文:
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
答案4
得分: 8
$ unset GOROOT
对我有用。正如大多数答案所建议的那样,你的 GOROOT 是无效的。
英文:
$ unset GOROOT
worked for me. As most answers suggest your GOROOT is invalid.
答案5
得分: 7
因为GFW禁止你访问golang.org!当我使用代理时,它可以正常工作。
你可以使用以下命令查看信息:
go get -v -u golang.org/x/oauth2
英文:
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
答案6
得分: 2
我在MacOS 10.10上遇到了同样的问题。我发现问题是由OhMyZsh shell引起的。然后我切换回bash,一切都正常了。
这是我的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"
英文:
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
答案7
得分: 2
最常见的原因有:
- GOROOT 配置不正确
或者 - GOPATH 未设置
英文:
The most common causes are:
- An incorrectly configured GOROOT
OR - GOPATH is not set
答案8
得分: 0
我在将go1.2升级到go1.4之后遇到了同样的问题。
我将GOPATH中的src文件夹重命名为_src,然后执行了go get -v
命令。
这样做后问题解决了,然后我删除了_src文件夹。
希望对你有帮助。
英文:
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.
答案9
得分: 0
我在安装不同的软件包时遇到了这个问题,可能是由于您的路径上的GOROOT和GOPATH配置引起的。我倾向于不设置GOROOT,因为我的OS X安装已经为我处理了(我相信)。
-
确保在您的.profile文件(或者您存储配置文件的位置:.bash_profile、.zshrc、.bashrc等)中包含以下内容:
export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin
-
另外,您可能还想要取消设置GOROOT,以防该路径也不正确。
-
此外,在GOPATH分配之前,请确保清理您的PATH,类似于我下面所做的操作:
export PATH=$HOME/bin:/usr/local/bin:$PATH export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin
-
然后,执行
source <.profile>
以激活配置。 -
重试
go get
命令。
英文:
I encountered this issue when installing a different package, and it could be caused by the GOROOT and GOPATH configuration on your PATH. I tend not to set GOROOT because my OS X installation handled it (I believe) for me.
-
Ensure the following in your .profile (or wherever you store profile configuration: .bash_profile, .zshrc, .bashrc, etc):
export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin
-
Also, you likely want to
unset GOROOT
, as well, in case that path is also incorrect. -
Furthermore, be sure to clean your PATH, similarly to what I've done below, just before the GOPATH assignment, i.e.:
export PATH=$HOME/bin:/usr/local/bin:$PATH export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin
-
Then,
source <.profile>
to activate -
retry
go get
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论