在golang中找不到包“github.com/user../../”

问题描述 投票:-4回答:1

我正在尝试从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 installgo 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
go github build glide-golang
1个回答
0
投票

如果您尚未设置任何go路径,则会出现此问题。有必要。

我假设你是命令行snap,你是UNIX用户。谷歌官方文档建议您手动设置go路径。 $ GOROOT是可选的,但如果你想获得第三方库,必须设置$ GOPATH。

编辑〜/ .bash_profile以添加以下行:

export GOPATH=$HOME/work

然后注销并登录或使用source ~/.bash_profile您可以从here阅读更多内容。假设您的Golang包目录位于work目录中的home文件夹中。工作文件夹的目录结构必须如下所示,

  • 工作 SRC PKG 箱子
© www.soinside.com 2019 - 2024. All rights reserved.