Go包导入自身,并且在GOPATH中找不到自身。

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

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/&lt;user&gt;/aRepo and in its own import statement have import &quot;github.com/&lt;user&gt;/aRepo&quot;. So it imports itself using a the "go gettable" path. Sometimes this works fine; however, sometimes I get

package github.com/&lt;user&gt;/aRepo
imports github.com/&lt;user&gt;/aRepo
imports github.com/&lt;user&gt;/aRepo: cannot find package &quot;github.com/&lt;user&gt;/aRepo&quot; in any of:
/usr/local/go/src/github.com/&lt;user&gt;/aRepo (from $GOROOT)
/home/me/go/src/github.com/&lt;user&gt;/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=&quot;amd64&quot;
GOBIN=&quot;&quot;
GOCHAR=&quot;6&quot;
GOEXE=&quot;&quot;
GOHOSTARCH=&quot;amd64&quot;
GOHOSTOS=&quot;linux&quot;
GOOS=&quot;linux&quot;
GOPATH=&quot;:/home/vagrant/go&quot;
GORACE=&quot;&quot;
GOROOT=&quot;/usr/local/go&quot;
GOTOOLDIR=&quot;/usr/local/go/pkg/tool/linux_amd64&quot;
CC=&quot;gcc&quot;
GOGCCFLAGS=&quot;-fPIC -m64 -pthread -fmessage-length=0&quot;
CXX=&quot;g++&quot;
CGO_ENABLED=&quot;1&quot;

答案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.

huangapple
  • 本文由 发表于 2016年1月22日 09:13:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/34937374.html
匿名

发表评论

匿名网友

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

确定