2016-12-05 15:06
浏览 277

“执行安装”将找不到软件包“ 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.

图片转代码服务由CSDN问答提供 功能建议

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

当尝试通过 https://golang.org/doc/install#testing 我收到以下错误:

 < 代码> $去安装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
 / home / user / go / src / pkg / runtime(从$ GOROOT开始)
 / home / user / work / src / runtime(从$ GOPATH开始)
  <  / pre> 

检查〜/ go,我在〜/ go / src / fmt中找到了fmt,而不是〜/ go / src / pkg / fmt

就像我缺少重要的东西。 感谢您的帮助。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyinjiao9351 2016-12-05 15:28

    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.

    解决 无用
    打赏 举报
  • dpwqicw157673 2018-08-06 21:31

    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:


    解决 无用
    打赏 举报

相关推荐 更多相似问题