英文:
golang remote imports fail
问题
我刚刚使用Homebrew安装了Golang,但在导入远程包时遇到了问题。
当我尝试安装包含以下内容的demo.go文件时:
import "github.com/bradfitz/gomemcache/memcache"
我收到以下错误信息:
$ go install
demo.go:3:8: 找不到包"github.com/bradfitz/gomemcache/memcache",在以下任何位置都找不到:
/usr/local/Cellar/go/1.4/libexec/src/github.com/bradfitz/gomemcache/memcache (来自$GOROOT)
/Users/white/go/src/github.com/bradfitz/gomemcache/memcache (来自$GOPATH)
在我这个初学者的眼中,它似乎只是在我的GOPATH本地查找。
英文:
I just install golang with homebrew and I am having trouble importing remote packages.
when I try to instal demo.go which contains
import "github.com/bradfitz/gomemcache/memcache"
I get the following error
$ go install
demo.go:3:8: cannot find package "github.com/bradfitz/gomemcache/memcache" in any of:
/usr/local/Cellar/go/1.4/libexec/src/github.com/bradfitz/gomemcache/memcache (from $GOROOT)
/Users/white/go/src/github.com/bradfitz/gomemcache/memcache (from $GOPATH)
To my untrained eyes it looks like it is just looking locally on my GOPATH.
答案1
得分: 13
这意味着你需要先获取它:
go get github.com/bradfitz/gomemcache/memcache
这是bradfitz/gomemcache
推荐的方法。
英文:
That means you need to get it first:
go get github.com/bradfitz/gomemcache/memcache
That is what the bradfitz/gomemcache
recommends.
答案2
得分: 5
你的眼睛没有被愚弄:Go编译器只会查找存储在本地的代码。
然而,go get
工具可以用来获取存储在远程代码库中的代码并将其复制到本地。所以,如果你输入:
go get github.com/bradfitz/gomemcache/memcache
你将在$GOPATH/src/github.com/bradfitz/gomemcache/memcache
中拥有一份代码副本。
注意,github.com/bradfitz/gomemcahce/memcache
实际上是一个本地目录路径,所以你可以使用import "github.com/bradfitz/gomemcache/memcache"
来在你的代码中导入它。它只是恰好也是go get
工具知道如何获取的远程代码库的名称。
英文:
Your untrained eyes are not fooling you: the go compiler will only look for code that is stored locally.
The go get
tool, however, can be used to fetch code that is stored in a remote repository and copy it over locally. So, if you type:
go get github.com/bradfitz/gomemcache/memcache
you will have a copy of the code in $GOPATH/src/github.com/bradfitz/gomemcache/memcache
Notice that github.com/bradfitz/gomemcahce/memcache
is actually a local directory path, so you use import "github.com/bradfitz/gomemcache/memcache"
to import it in your code. It just happens to also be the name of a remote repository that the go get
tool knows how to fetch.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论