1

我正在尝试安装我的项目的依赖项,glide但不幸的是它失败并显示以下消息:

main.go:7:2: cannot find package "github.com/arschles/go-in-5-minutes/episode13/models" in any of:
    /Users/theo/go-workspace/src/github.com/thitami/go-in-5-minutes/episode13/vendor/github.com/arschles/go-in-5-minutes/episode13/models (vendor tree)
    /usr/local/Cellar/go/1.8.3/libexec/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOROOT)
    /Users/theo/go-workspace/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOPATH)

运行 a go env,这是我感兴趣的环境变量:

GOPATH="/Users/theo/go-workspace"
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"

请注意,我zsh正在导出文件GOPATH内部,.zshrc如下所示:

export GOPATH=HOME/go-workspace

任何想法表示赞赏

* 更新 *

根据要求,这是调用models包的一段代码:

import (
    "database/sql"
    "log"

    "github.com/arschles/go-in-5-minutes/episode13/models"
    _ "github.com/mxk/go-sqlite/sqlite3"
)
4

1 回答 1

1

您只能设置一次 gopath,并且每次更改软件包时都必须重新设置它。把它想象成一个虚拟环境。一种解决方法是全局安装软件包或使用 gvm 之类的东西

于 2017-07-15T16:38:21.683 回答