我正在尝试使用 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
,这是我感兴趣的环境变量:
GOPATH="/Users/theo/go-workspace"
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
请注意,我是 zsh
,我正在导出 .zshrc
文件中的 GOPATH
,如下所示:
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"
)
最佳答案
您只能设置一次 gopath,每次更改包时都必须重新设置。把它想象成一个 virtualenv。一种解决方法是全局安装包或使用类似 gvm 的东西
关于go - 在 GOPATH 下找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45084909/