英文:
Cannot find package under GOPATH
问题
我正在尝试使用glide
安装我的项目的依赖项,但不幸的是,它失败并显示以下消息:
main.go:7:2: 找不到包"github.com/arschles/go-in-5-minutes/episode13/models",它位于以下任何位置:
/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 ($GOROOT)
/Users/theo/go-workspace/src/github.com/arschles/go-in-5-minutes/episode13/models ($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"
)
英文:
I am trying to install the dependencies of my project with glide
but unfortunately it fails with the following message:
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)
Running a go env
, this is my env variables of interest:
GOPATH="/Users/theo/go-workspace"
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
Please be advised that I am zsh
and I am exporting the GOPATH
inside the .zshrc
file like this:
export GOPATH=HOME/go-workspace
Any ideas are appreciated
*** UPDATE ***
As requested this is the piece of code with the call to the models
package:
import (
"database/sql"
"log"
"github.com/arschles/go-in-5-minutes/episode13/models"
_ "github.com/mxk/go-sqlite/sqlite3"
)
答案1
得分: 1
你只能设置一次gopath,并且每次更改包时都必须重新设置它。可以将其视为virtualenv。解决这个问题的一种方法是全局安装包,或者使用类似gvm的工具。
英文:
You can only set the gopath once and you'll have to reset it every time you change packages. Think of it as a virtualenv. One way around it is to install the packages global or by using something like gvm
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论