繁体   English   中英

如何在 Go 中安装需求? “找不到包裹”

[英]How do I install requirements in Go? "cannot find package"

我是 Go 新手,我正在尝试使用最少的文档建立一个 Go 项目: https ://github.com/alphagov/metadata-api

我已经克隆了它,但是当我尝试go build时,我收到以下警告:

main.go:8:2: cannot find package "github.com/Sirupsen/logrus" in any of:
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/github.com/Sirupsen/logrus (from $GOROOT)
    /Users/me/go/src/github.com/Sirupsen/logrus (from $GOPATH)
main.go:14:2: cannot find package "github.com/alphagov/metadata-api/content_api" in any of:
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/github.com/alphagov/metadata-api/content_api (from $GOROOT)
    /Users/me/go/src/github.com/alphagov/metadata-api/content_api (from $GOPATH)

我猜这是因为我还没有安装 Go 的等效要求?

我的GOPATH已设置:

metadata-api$ echo $GOPATH
/Users/me/go

Go 可执行文件在

metadata-ape$ echo $PATH
....:/Users/me/go/bin

我需要做些什么来帮助 Go 找到这些包?

您应该先安装软件包:

尝试

$ go get github.com/Sirupsen/logrus

并检查你$GOPATH目录

这个项目使用gom作为包管理器,

确保你已经安装了gom

或者试试这个命令

$ gom install 

我认为你的$GOPATH$PATH设置不正确, $GOPATH环境变量指定了你的工作空间的位置,这些是我的路径设置:

export GOROOT=$HOME/bin/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/golang
export PATH=$PATH:$GOBIN

我有类似的问题和

export GO111MODULE=on 

有帮助。

能够通过键入以下内容修复 Go 1.13.7 中的类似问题:

 export GOPATH=~/go
 go get github.com/profile/repository 
 (e.g. github.com/Sirupsen/logrus)

当你需要你的代码做一些其他人可能已经实现的事情时(在 Github 或其他地方的包中),你应该在你的文件夹中初始化 go mod 文件。)

出于理解的目的,只需使用example.com/module。

go mod init example.com/module

添加新的模块要求和总和。

保持整洁

运行你的程序

去跑步 。

更多详情: https : //golang.org/doc/tutorial/getting-started

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM