我正在尝试从github源代码构建一个项目。我找到了一些导入包的源代码,如下所示:
import (
"os"
"github.com/bivas/rivi/commands"
"github.com/mitchellh/cli"
)
但是,每次构建项目时都会抛出错误:
user-MacBook-Pro:rivi user$ go build rivi.go
rivi.go:6:2: cannot find package "github.com/bivas/rivi/commands" in any of:
/usr/local/Cellar/go/1.7.5/libexec/src/github.com/bivas/rivi/commands (from $GOROOT)
($GOPATH not set)
rivi.go:8:2: cannot find package "github.com/mitchellh/cli" in any of:
/usr/local/Cellar/go/1.7.5/libexec/src/github.com/mitchellh/cli (from $GOROOT)
($GOPATH not set)
如何构建此项目。目前我正在尝试将这个project构建到我的系统中。
编辑:
运行此命令后go install
或go get
:
package github.com/bivas/rivi/commands: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/connectors/github: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/autoassign: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/automerge: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/commenter: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/labeler: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/locker: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/sizing: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/slack: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/status: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/trigger: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/mitchellh/cli: cannot download, $GOPATH not set. For more details see: go help gopath
答案 0 :(得分:3)
这个问题已经有几年了。我遇到了同样的问题。我的解决方案是我需要运行 go mod init [name_of_main_go_file]
,它会创建 go.mod 文件。然后你可以运行 go run .
答案 1 :(得分:0)
如果您还没有设置任何go路径,这个问题很常见。这是必要的。
我假设你是命令行,你是UNIX用户。谷歌官方文档建议您手动设置go路径。 $ GOROOT是可选的,但是如果你想要获得第三方库,必须设置$ GOPATH。
编辑〜/ .bash_profile以添加以下行:
export GOPATH=$HOME/work
然后退出并登录或使用source ~/.bash_profile
您可以从here了解更多信息。假设您的Golang包目录位于work
目录中的home
文件夹中。工作文件夹的目录结构必须如下所示,