在 GOPATH 下找不到包
Cannot find package under 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
,这是我感兴趣的环境变量:
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
我正在尝试使用 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