簡體   English   中英

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

[英]cannot find package “github.com/user../../” in golang while building

我正在嘗試從 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)

如何構建這個項目。 目前我正在嘗試將這個項目構建到我的系統中。

編輯:

運行此命令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 mod init [name_of_main_go_file] ,它會創建 go.mod 文件。 然后你可以運行go run .

https://golang.org/doc/tutorial/getting-started#call

如果您還沒有設置任何 go 路徑,這個問題很常見。 這是必要的。

我從您的命令行快照中假設您是 UNIX 用戶。 Google 的官方文檔建議您手動設置 go 路徑。 $GOROOT 是可選的,但如果您嘗試獲取第三方庫,則必須設置 $GOPATH。

編輯您的 ~/.bash_profile 以添加以下行:

export GOPATH=$HOME/work

然后注銷並登錄或使用source ~/.bash_profile您可以從這里閱讀更多信息 假設您的 Golang 包目錄位於您的home目錄內的work文件夾中。 工作文件夾的目錄結構必須如下所示,

  • 工作
    • 源文件
    • 垃圾桶

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM