[英]How do I install requirements in Go? "cannot find package"
I'm new to Go and I'm trying to set up a Go project with minimal documentation: https://github.com/alphagov/metadata-api我是 Go 新手,我正在尝试使用最少的文档建立一个 Go 项目: https ://github.com/alphagov/metadata-api
I've cloned it, but when I try go build
I get the following warnings:我已经克隆了它,但是当我尝试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)
I'm guessing this is because I haven't installed the Go equivalent of requirements?我猜这是因为我还没有安装 Go 的等效要求?
My GOPATH
is set:我的GOPATH
已设置:
metadata-api$ echo $GOPATH
/Users/me/go
And the Go executable is in Go 可执行文件在
metadata-ape$ echo $PATH
....:/Users/me/go/bin
What do I need to do to help Go find these packages?我需要做些什么来帮助 Go 找到这些包?
You should install package first:您应该先安装软件包:
try尝试
$ go get github.com/Sirupsen/logrus
and check you $GOPATH
dir并检查你$GOPATH
目录
This project use gom
as the package manager,这个项目使用gom
作为包管理器,
Make sure you have installed gom
确保你已经安装了gom
or try this command或者试试这个命令
$ gom install
I think your $GOPATH
and $PATH
settings are incorrect, the $GOPATH
environment variable specifies the location of your workspace, these are my path settings:我认为你的$GOPATH
和$PATH
设置不正确, $GOPATH
环境变量指定了你的工作空间的位置,这些是我的路径设置:
export GOROOT=$HOME/bin/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/golang
export PATH=$PATH:$GOBIN
I had similar issue and我有类似的问题和
export GO111MODULE=on
helped.有帮助。
Was able to fix the similar issue in Go 1.13.7 by typing:能够通过键入以下内容修复 Go 1.13.7 中的类似问题:
export GOPATH=~/go
go get github.com/profile/repository
(e.g. github.com/Sirupsen/logrus)
When you need your code to do something that might have been implemented by someone else (in Github or somewhere else package), You should initialize go mod file inside of your folder.)当你需要你的代码做一些其他人可能已经实现的事情时(在 Github 或其他地方的包中),你应该在你的文件夹中初始化 go mod 文件。)
For the purposes of this understand, just use example.com/module.出于理解的目的,只需使用example.com/module。
go mod init example.com/module go mod init example.com/module
Add new module requirements and sums.添加新的模块要求和总和。
go mod tidy保持整洁
Run your program运行你的程序
go run .去跑步 。
For more details: https://golang.org/doc/tutorial/getting-started更多详情: https : //golang.org/doc/tutorial/getting-started
"...Starting in Go 1.13, module mode will be the default for all development..." “...从 Go 1.13 开始,模块模式将成为所有开发的默认模式...”
"...When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin)..." “......使用模块时,GOPATH不再用于解析导入。但是,它仍然用于存储下载的源代码(在GOPATH/pkg/mod中)和编译的命令(在GOPATH/bin中)......”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.