Golang 远程导入失败

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

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.

huangapple
  • 本文由 发表于 2015年1月15日 14:03:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/27957616.html
匿名

发表评论

匿名网友

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

确定