获取错误 – 无法加载包

huangapple go评论83阅读模式
英文:

go get error - can't load package

问题

我是你的中文翻译助手,以下是翻译好的内容:

我是golang的新手,我正在尝试获取一个包,但是我遇到了一个奇怪的错误,似乎无法找出问题在哪里?

padlar@padlar:~/workspace-go$ echo $GOPATH
/home/padlar/workspace-go

padlar@padlar:~/workspace-go$ go get golang.org/x/oauth2
padlar@padlar:~/workspace-go$ ls ~/workspace-go/src/golang.org/x/oauth2/
AUTHORS google/ jwt_test.go README.md
CONTRIBUTORS internal/ LICENSE transport.go
example_test.go jws/ oauth2.go transport_test.go
.git/ jwt.go oauth2_test.go .travis.yml

padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2
oauth2/ oauth2.a
padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2/
internal.a jws.a
padlar@padlar:~/workspace-go$ go get github.com/golang/oauth2
无法加载包:包github.com/golang/oauth2:目录/home/padlar/workspace-go/src/github.com/golang/oauth2中的代码需要导入"golang.org/x/oauth2"。

英文:

I am new to golang and I am trying to get a package but I get a strange error and can't seem to figure out what the problem is?

padlar@padlar:~/workspace-go$ echo $GOPATH
/home/padlar/workspace-go

padlar@padlar:~/workspace-go$ go get golang.org/x/oauth2
padlar@padlar:~/workspace-go$ ls ~/workspace-go/src/golang.org/x/oauth2/
    AUTHORS            google/            jwt_test.go        README.md          
    CONTRIBUTORS       internal/          LICENSE            transport.go       
    example_test.go    jws/               oauth2.go          transport_test.go  
    .git/              jwt.go             oauth2_test.go     .travis.yml        

padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2
oauth2/   oauth2.a  
padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2/
internal.a  jws.a
padlar@padlar:~/workspace-go$ go get github.com/golang/oauth2
can't load package: package github.com/golang/oauth2: code in directory /home/padlar/workspace-go/src/github.com/golang/oauth2 expects import "golang.org/x/oauth2"

答案1

得分: 17

您正在使用go get命令来获取两个不同的导入路径。新的路径是:

go get golang.org/x/oauth2

而旧的路径是:

go get github.com/golang/oauth2

这会让Go工具链感到困惑。请始终使用新的导入路径:

go get golang.org/x/oauth2
英文:

You are using go get on two different import paths. The new path,

go get golang.org/x/oauth2

and the old path

go get github.com/golang/oauth2

This confuses the Go tool chain. Consistently use the new import path

go get golang.org/x/oauth2

huangapple
  • 本文由 发表于 2014年12月7日 23:09:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/27344013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定