无法在GOPATH下找到包。

huangapple go评论68阅读模式
英文:

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 glidebut 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

huangapple
  • 本文由 发表于 2017年7月13日 23:19:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/45084909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定