英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论