2019-01-20 14:41
浏览 42


go run and go build are not geting dependencies.

What I did:

  • I have done a go get of a package, it fetched it, and its dependencies, and build it. (all is good)
  • I run its command-line example program. (all is good)
  • I then created a new program based on this example, and go run it. (all is good)
  • Then copied this example program, and go run it. ( get a dependency error ).


#↳ go version
go version go1.11.4 linux/amd64

#↳ echo $GOPATH

#↳ go get -u

#↳ cp -T $GOPATH/src/ my-mustache.go

#↳ go build -v my-mustache.go
my-mustache.go:8:2: cannot find package "" in any of:
    /usr/local/go/src/ (from $GOROOT)
    /go/src/ (from $GOPATH)

I can see why it is not already installed: it was in a vendor sub-directory of the original source code. But why does it not install, when I build?

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

运行 go build 不是


  • 我已经完成了一个软件包的获取,它 获取它及其依赖项并进行构建。 (一切都很好)
  • 我运行其命令行示例程序。 (一切都很好)
  • 然后我根据此示例创建了一个新程序,并 go run 。 (一切都很好)
  • 然后复制了此示例程序,并开始运行。 (获取依赖项错误)。

     #↳go version 
    go version go1.11.4 linux  / amd64 
    #↳echo $ GOPATH 
     / home / ???? / + Files / workshops / programming / golang / gopath 
    #↳go -u。  .. 
    #↳cp -T $ GOPATH / src / / cbroglie / mustache / cmd / mustache / main.go my-mustache.go 
    #↳建立-v my-mustache。  go 
     /usr/local/go/src/来自$ GOROOT  )
     /go/src/来自$ GOPATH)

    我可以看到为什么尚未安装它:它在 原始源代码的供应商子目录。 但是,为什么在我构建时不安装?

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

1条回答 默认 最新

  • dpicx06888 2019-01-20 15:55

    Check first your $GOPATH/bin folder: a go get -u should already have compiled and installed all relevant binaries in it.

    The README mentions:

    To install mustache.go, simply run go get

    It looks like the mustache package is installed and working.
    However when I try to build the cli example, it needs another package, if I go get it then all is well, however I was expecting go build to install all needed packages.
    Am I wrong?

    go build itself won't install dependencies, so you need to go get it, or activate go 1.11 modules and declare that dependencies in your new program modules.

    解决 无用
    打赏 举报

相关推荐 更多相似问题