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

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

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"获取的路径进行自我导入。有时这样做是可以正常工作的,但有时我会遇到以下错误:

  1. package github.com/<user>/aRepo
  2. imports github.com/<user>/aRepo
  3. imports github.com/<user>/aRepo: cannot find package "github.com/<user>/aRepo" in any of:
  4. /usr/local/go/src/github.com/<user>/aRepo (from $GOROOT)
  5. /home/me/go/src/github.com/<user>/aRepo (from $GOPATH)

我使用以下命令设置了我的GOPATH:

  1. export GOPATH=$GOPATH:/home/me/go:`godep path`

不清楚为什么会发生这种情况,有什么想法吗?

编辑

我的go env

  1. GOARCH="amd64"
  2. GOBIN=""
  3. GOCHAR="6"
  4. GOEXE=""
  5. GOHOSTARCH="amd64"
  6. GOHOSTOS="linux"
  7. GOOS="linux"
  8. GOPATH=":/home/vagrant/go"
  9. GORACE=""
  10. GOROOT="/usr/local/go"
  11. GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
  12. CC="gcc"
  13. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
  14. CXX="g++"
  15. 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

  1. package github.com/&lt;user&gt;/aRepo
  2. imports github.com/&lt;user&gt;/aRepo
  3. imports github.com/&lt;user&gt;/aRepo: cannot find package &quot;github.com/&lt;user&gt;/aRepo&quot; in any of:
  4. /usr/local/go/src/github.com/&lt;user&gt;/aRepo (from $GOROOT)
  5. /home/me/go/src/github.com/&lt;user&gt;/aRepo (from $GOPATH)

I set my GOPATH with:

  1. 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:

  1. GOARCH=&quot;amd64&quot;
  2. GOBIN=&quot;&quot;
  3. GOCHAR=&quot;6&quot;
  4. GOEXE=&quot;&quot;
  5. GOHOSTARCH=&quot;amd64&quot;
  6. GOHOSTOS=&quot;linux&quot;
  7. GOOS=&quot;linux&quot;
  8. GOPATH=&quot;:/home/vagrant/go&quot;
  9. GORACE=&quot;&quot;
  10. GOROOT=&quot;/usr/local/go&quot;
  11. GOTOOLDIR=&quot;/usr/local/go/pkg/tool/linux_amd64&quot;
  12. CC=&quot;gcc&quot;
  13. GOGCCFLAGS=&quot;-fPIC -m64 -pthread -fmessage-length=0&quot;
  14. CXX=&quot;g++&quot;
  15. 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:

确定