How do I install requirements in Go? “cannot find

2020-02-17 08:34发布

I'm new to Go and I'm trying to set up a Go project with minimal documentation: https://github.com/alphagov/metadata-api

I've cloned it, but when I try go build I get the following warnings:

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?

My GOPATH is set:

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

And the Go executable is in

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

What do I need to do to help Go find these packages?

标签: go
3条回答
别忘想泡老子
2楼-- · 2020-02-17 09:10

I had similar issue and

export GO111MODULE=on 

helped.

查看更多
Anthone
3楼-- · 2020-02-17 09:11

Was able to fix the similar issue in Go 1.13.7 by typing:

 export GOPATH=~/go
 go get github.com/profile/repository 
 (e.g. github.com/Sirupsen/logrus)
查看更多
走好不送
4楼-- · 2020-02-17 09:12

You should install package first:

try

$ go get github.com/Sirupsen/logrus

and check you $GOPATH dir

This project use gom as the package manager,

Make sure you have installed 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:

export GOROOT=$HOME/bin/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/golang
export PATH=$PATH:$GOBIN
查看更多
登录 后发表回答