美文网首页
package 'xxx' is not in GOROOT

package 'xxx' is not in GOROOT

作者: 落日彼岸 | 来源:发表于2020-06-28 20:10 被阅读0次

    项目 go run main.go 时报错

    go env 查看环境

    如果要用 gopath 模式 引入包 从src目录下开始引入 需要关闭 go mod 模式

    export GO111MODULE=off

    ../github.com/go-playground/universal-translator/errors.go:7:2: cannot find package "github.com/go-playground/locales" in any of:
        /usr/local/go/src/github.com/go-playground/locales (from $GOROOT)
        /Users/jerryzhb/go/src/github.com/go-playground/locales (from $GOPATH)
    ../github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
        /usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
        /Users/jerryzhb/go/src/github.com/golang/protobuf/proto (from $GOPATH)
    ../github.com/go-playground/validator/baked_in.go:19:2: cannot find package "github.com/leodido/go-urn" in any of:
        /usr/local/go/src/github.com/leodido/go-urn (from $GOROOT)
        /Users/jerryzhb/go/src/github.com/leodido/go-urn (from $GOPATH)
    ../github.com/gin-gonic/gin/logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
        /usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT)
        /Users/jerryzhb/go/src/github.com/mattn/go-isatty (from $GOPATH)
    ../github.com/gin-gonic/gin/binding/msgpack.go:14:2: cannot find package "github.com/ugorji/go/codec" in any of:
        /usr/local/go/src/github.com/ugorji/go/codec (from $GOROOT)
        /Users/jerryzhb/go/src/github.com/ugorji/go/codec (from $GOPATH)
    ../github.com/gin-gonic/gin/binding/yaml.go:12:2: cannot find package "gopkg.in/yaml.v2" in any of:
        /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
        /Users/jerryzhb/go/src/gopkg.in/yaml.v2 (from $GOPATH)
    

    如果使用go mod 模式

    export GO111MODULE=on

    并且在目录下执行 go mod init

    目录下产生两个文件

    go.mod
    go.sum
    

    否则就会报错

    main.go:15:2: package tinybg/conf is not in GOROOT (/usr/local/go/src/tinybg/conf)
    main.go:16:2: package tinybg/utils is not in GOROOT (/usr/local/go/src/tinybg/utils)
    

    相关文章

      网友评论

          本文标题:package 'xxx' is not in GOROOT

          本文链接:https://www.haomeiwen.com/subject/rzfgfktx.html