未解决供应商目录中的依赖关系。

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

Not resolving dependency in vendor directory

问题

我正在运行go1.6,在GOPATH(/Users/bweidlich/Projects/go)中运行"go build"时遇到以下错误:

main.go:6:2: 无法在以下任何位置找到包"github.com/spf13/viper":
/usr/local/go/src/github.com/spf13/viper(来自$GOROOT)
/Users/bweidlich/Projects/go/src/github.com/spf13/viper(来自$GOPATH)

项目结构:

bin/
glide.lock
glide.yaml
go.iml
logs/
main.go
pkg/
src/
vendor/
      github.com/
                 deckarep/gosx-notifier
                 spf13/viper
                 gizak/termui

main.go

package main

import (
	"fmt"
	"github.com/gizak/termui" <--- 无法解析
	"github.com/spf13/viper"  <--- 无法解析
	"log"
	"bweidlich/dash"
	"net/http"
	"os"
	"os/exec"
	"time"
)
英文:

I'm running go1.6 and am getting the follow error when running "go build" in GOPATH (/Users/bweidlich/Projects/go)

main.go:6:2: cannot find package &quot;github.com/spf13/viper&quot; in any of:
/usr/local/go/src/github.com/spf13/viper (from $GOROOT)
/Users/bweidlich/Projects/go/src/github.com/spf13/viper (from $GOPATH)

Project structure:

bin/
glide.lock
glide.yaml
go.iml
logs/
main.go
pkg/
src/
vendor/
      github.com/
                 deckarep/gosx-notifier
                 spf13/viper
                 gizak/termui

main.go

package main

import (
	&quot;fmt&quot;
	&quot;github.com/gizak/termui&quot; &lt;--- doesn&#39;t resolve
	&quot;github.com/spf13/viper&quot;  &lt;--- doesn&#39;t resolve
	&quot;log&quot;
	&quot;bweidlich/dash&quot;
	&quot;net/http&quot;
	&quot;os&quot;
	&quot;os/exec&quot;
	&quot;time&quot;
)

答案1

得分: 5

你的main.go文件需要放在一个工作空间(即gopath内)中,以便其依赖项可以被供应。作为一个测试,尝试将你的main.go放在一个虚假的路径中,看看是否可以找到供应的依赖项:

$GOPATH/src/
   example.com/
     main.go
   vendor/
     github.com/
       spf13/viper/
       gizak/termui/

一般来说,你不应该将任何代码存储在gopath的根目录src之外的位置。也就是说,你应该模仿go get在创建目录时使用的结构。

英文:

Your main.go file needs to be inside a workspace (that is, inside gopath) for its dependencies to be vendored. As a test, try putting your main.go inside a fake path and see if the vendored deps are found:

$GOPATH/src/
   example.com/
     main.go
   vendor/
     github.com/
       spf13/viper/
       gizak/termui/

In general, you don't want to store any code in your gopath outside its root src directory. That is, you should echo the structure that go get would use when creating the directories.

huangapple
  • 本文由 发表于 2016年3月21日 05:27:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/36119814.html
匿名

发表评论

匿名网友

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

确定