在GOPATH下找不到包

时间:2017-07-13 15:19:11

标签: go gopath

我正在尝试使用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)

运行go env,这是我感兴趣的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"
)

1 个答案:

答案 0 :(得分:1)

您只能设置一次gopath,每次更改包时都必须重置它。把它想象成一个虚拟的人。解决这个问题的一种方法是全局安装软件包或使用gvm

之类的东西