‘go install’ 无法找到包 “fmt”。

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

'go install' will not find package "fmt"

问题

我通过将go 1.7.4解压到~/go并相应地设置GOROOT来安装了它。我还创建了~/work/src/github.com/user/hello并相应地设置了GOPATH。

当我尝试从https://golang.org/doc/install#testing中的hello world示例时,我遇到了以下错误:

$ go install github.com/user/hello
../work/src/github.com/user/hello/hello.go:3:8: 找不到包"fmt",它位于以下任何位置中:
/home/user/go/src/pkg/fmt(来自$GOROOT)
/home/user/work/src/fmt(来自$GOPATH)
package github.com/user/hello
导入runtime时出错:找不到包"runtime",它位于以下任何位置中:
/home/user/go/src/pkg/runtime(来自$GOROOT)
/home/user/work/src/runtime(来自$GOPATH)

在检查~/go后,我发现fmt在~/go/src/fmt而不是~/go/src/pkg/fmt中。

感觉我漏掉了一些关键的东西。感谢您的帮助。

英文:

I installed go 1.7.4 by untarring it into ~/go and setting GOROOT accordingly. I also created ~/work/src/github.com/user/hello and set GOPATH accordingly.

When trying the hello world example from https://golang.org/doc/install#testing I get the following error:

$ go install github.com/user/hello
    ../work/src/github.com/user/hello/hello.go:3:8: cannot find package "fmt" in any of:
    /home/user/go/src/pkg/fmt (from $GOROOT)
    /home/user/work/src/fmt (from $GOPATH)
package github.com/user/hello
    imports runtime: cannot find package "runtime" in any of:
    /home/user/go/src/pkg/runtime (from $GOROOT)
    /home/user/work/src/runtime (from $GOPATH)

Checking ~/go, I find fmt in ~/go/src/fmt and not ~/go/src/pkg/fmt

It feels like I am missing something crucial. Thankful for assistance.

答案1

得分: 7

如果您之前通过软件包管理器安装了Go,可能会有旧版本。检查go version并在需要时删除旧版本。

英文:

If you installed Go from a package manager before, you might have an old version. Check go version and remove the old version if needed.

答案2

得分: 2

对于已安装了 go 1.10.3 的 MacPorts 用户来说,它似乎没有正确安装。运行时标准包丢失了。我甚至尝试卸载并重新安装了一个干净的副本。所以我只是将其移除,并从 Google 获取了官方的 Darwin 二进制包:

https://golang.org/dl/

英文:

For MacPorts users with e.g. go 1.10.3 installed, it didn't seem to be correctly installed for me. The runtime standard packages were missing. I even tried uninstalling and reinstalling a clean copy. So I just removed it and got the official darwin binary package from google:

https://golang.org/dl/

huangapple
  • 本文由 发表于 2016年12月5日 23:06:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/40977283.html
匿名

发表评论

匿名网友

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

确定