英文:
Go package imports self, and can't find itself in it the GOPATH
问题
有时候,我会使用一个带有类似于go get github.com/<user>/aRepo
的go包,并在自己的导入语句中使用import "github.com/<user>/aRepo"
。所以它使用可通过"go get"获取的路径进行自我导入。有时这样做是可以正常工作的,但有时我会遇到以下错误:
package github.com/<user>/aRepo
imports github.com/<user>/aRepo
imports github.com/<user>/aRepo: cannot find package "github.com/<user>/aRepo" in any of:
/usr/local/go/src/github.com/<user>/aRepo (from $GOROOT)
/home/me/go/src/github.com/<user>/aRepo (from $GOPATH)
我使用以下命令设置了我的GOPATH:
export GOPATH=$GOPATH:/home/me/go:`godep path`
不清楚为什么会发生这种情况,有什么想法吗?
编辑
我的go env
:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=":/home/vagrant/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
英文:
Every once in awhile, I'll use a go package that has a go get like : go get github.com/<user>/aRepo
and in its own import statement have import "github.com/<user>/aRepo"
. So it imports itself using a the "go gettable" path. Sometimes this works fine; however, sometimes I get
package github.com/<user>/aRepo
imports github.com/<user>/aRepo
imports github.com/<user>/aRepo: cannot find package "github.com/<user>/aRepo" in any of:
/usr/local/go/src/github.com/<user>/aRepo (from $GOROOT)
/home/me/go/src/github.com/<user>/aRepo (from $GOPATH)
I set my GOPATH with:
export GOPATH=$GOPATH:/home/me/go:`godep path`
It's very unclear as to why this would happen, any ideas as to why?
EDIT
my go env
:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=":/home/vagrant/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
答案1
得分: 2
原文翻译如下:
原来问题是权限问题,因为我在使用一个带有同步文件夹的vagrant虚拟机,vagrant将同步文件夹创建的整个路径设置为744 root:root。因此,作为非root用户,我无法向该文件夹写入,所以错误消息实际上是来自godep尝试安装自身但找不到其源代码。
英文:
So it turns out it was a permissions issue since I was using a vagrant box with a synced folder, vagrant set the entire path that synced folder created as 744 root:root. Therefore, I could not write to that folder as a non-root user, so that error message is actually coming from godep trying to install itself and not finding its src.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论