简体   繁体   English

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

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

I am trying to build a project from github source code.我正在尝试从 github 源代码构建一个项目。 I have found some source code importing a package something like below:我发现了一些导入包的源代码,如下所示:

import (
    "os"

    "github.com/bivas/rivi/commands"
    "github.com/mitchellh/cli"
)

However, while building a project every time it throws an error:但是,在每次构建项目时都会抛出错误:

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)

how to build this project.如何构建这个项目。 Currently I am trying to build this one project into my system.目前我正在尝试将这个项目构建到我的系统中。

EDITED:编辑:

After running this command go install or go get :运行此命令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

This question is a few years old now.这个问题已经有几年了。 I was experiencing the same problem.我遇到了同样的问题。 The solution for me was that I needed to run go mod init [name_of_main_go_file] , which creates the go.mod file.我的解决方案是我需要运行go mod init [name_of_main_go_file] ,它会创建 go.mod 文件。 Then you can run go run .然后你可以运行go run .

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

This problem common if you haven't setup any go path yet.如果您还没有设置任何 go 路径,这个问题很常见。 It is necessary.这是必要的。

I am assuming from the command line snap of yours, that you are a UNIX user.我从您的命令行快照中假设您是 UNIX 用户。 Googles official doc recommend that you setup your go path manually . Google 的官方文档建议您手动设置 go 路径。 $GOROOT is optional but $GOPATH has to be set if you are trying to get third party libraries. $GOROOT 是可选的,但如果您尝试获取第三方库,则必须设置 $GOPATH。

Edit your ~/.bash_profile to add the following line:编辑您的 ~/.bash_profile 以添加以下行:

export GOPATH=$HOME/work

Then logout and login or use source ~/.bash_profile You can read more from here .然后注销并登录或使用source ~/.bash_profile您可以从这里阅读更多信息 Assuming your Golang package directory is in work folder inside your home directory.假设您的 Golang 包目录位于您的home目录内的work文件夹中。 The directory structure of work folder has to look like this,工作文件夹的目录结构必须如下所示,

  • work工作
    • src源文件
    • pkg
    • bin垃圾桶

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 golang测试错误:在以下任何位置都找不到软件包“ github.com/stretchr/testify/assert”: - golang test error: cannot find package “github.com/stretchr/testify/assert” in any of: 如何避免找不到包“ github.com/golang/protobuf/jsonpb”错误 - How to avoid cannot find package “github.com/golang/protobuf/jsonpb” error 在以下任何一个中找不到包“github.com/gorilla/mux”: - cannot find package “github.com/gorilla/mux” in any of: 软件包github.com/matcornic/hermes/v2:在以下任何位置都找不到软件包“ github.com/matcornic/hermes/v2”: - package github.com/matcornic/hermes/v2: cannot find package “github.com/matcornic/hermes/v2” in any of: golang:“去获取github.com/ ..”错误,“找不到头文件”-在哪里配置? - golang: “go get github.com/..” errors with “cannot find header file” - where is this configured? 无法安装 bleve,在任何地方都找不到 package “github.com/blevesearch/zap/v11” - Unable to install bleve, cannot find package “github.com/blevesearch/zap/v11” in any of 在以下任何一个中都找不到 package “github.com/jackc/pgx/v4”: - cannot find package “github.com/jackc/pgx/v4” in any of: go protobuf:找不到 package“。” 在 github.com/gogo/protobuf/proto 和 m.TimeStamp.MarshalToSizedBuffer 未定义 - go protobuf: Cannot find package "." in github.com/gogo/protobuf/proto and m.TimeStamp.MarshalToSizedBuffer undefined 尝试使用 docker-compose 时找不到 package “github.com/streadway/amqp” - cannot find package “github.com/streadway/amqp” when try to use docker-compose up github.com/golang/protobuf/protoc-gen-go 没有 golang 版本 1.18 的 package 路径 - github.com/golang/protobuf/protoc-gen-go has no package path for golang version 1.18
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM