无法从$ GOROOT和$ GOPATH找到包裹

时间:2017-04-10 13:48:58

标签: go gopath

尝试运行go build命令后我得到的错误的一小部分

go build ./...
trillian.pb.go:7:8: cannot find package "github.com/golang/protobuf/proto" in any of:
    /usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
    /Projects/Proj1/trillian/src/github.com/golang/protobuf/proto (from $GOPATH)

trillian.pb.go:11:8: cannot find package "github.com/golang/protobuf/ptypes/any" in any of:
    /usr/local/go/src/github.com/golang/protobuf/ptypes/any (from $GOROOT)
    /Projects/Proj1/trillian/src/github.com/golang/protobuf/ptypes/any (from $GOPATH)

trillian_admin_api.pb.go:12:8: cannot find package "github.com/golang/protobuf/ptypes/empty" in any of:
    /usr/local/go/src/github.com/golang/protobuf/ptypes/empty (from $GOROOT)
    /Projects/Proj1/trillian/src/github.com/golang/protobuf/ptypes/empty (from $GOPATH)

trillian.pb.go:10:8: cannot find package "github.com/google/trillian/crypto/sigpb" in any of:
    /usr/local/go/src/github.com/google/trillian/crypto/sigpb (from $GOROOT)
    /Projects/Proj1/trillian/src/github.com/google/trillian/crypto/sigpb (from $GOPATH)

trillian_admin_api.pb.gw.go:17:2: cannot find package "github.com/grpc-ecosystem/grpc-gateway/runtime" in any of:
    /usr/local/go/src/github.com/grpc-ecosystem/grpc-gateway/runtime (from  $GOROOT)
    /Projects/Proj1/trillian/src/github.com/grpc-ecosystem/grpc-gateway/runtime (from $GOPATH)

trillian_admin_api.pb.gw.go:18:2: cannot find package "github.com/grpc-ecosystem/grpc-gateway/utilities" in any of:
    /usr/local/go/src/github.com/grpc-ecosystem/grpc-gateway/utilities (from $GOROOT)
    /Projects/Proj1/trillian/src/github.com/grpc-ecosystem/grpc-gateway/utilities (from $GOPATH)

trillian_admin_api.pb.go:15:2: cannot find package "golang.org/x/net/context" in any of:
    /usr/local/go/src/golang.org/x/net/context (from $GOROOT)
    /Projects/Proj1/trillian/src/golang.org/x/net/context (from $GOPATH)

trillian_admin_api.pb.go:10:8: cannot find package "google.golang.org/genproto/googleapis/api/annotations" in any of:
    /usr/local/go/src/google.golang.org/genproto/googleapis/api/annotations (from $GOROOT)
    /Projects/Proj1/trillian/src/google.golang.org/genproto/googleapis/api/annotations (from $GOPATH)

trillian_log_api.pb.go:65:8: cannot find package "google.golang.org/genproto/googleapis/rpc/status" in any of:
    /usr/local/go/src/google.golang.org/genproto/googleapis/rpc/status (from $GOROOT)
    /Projects/Proj1/trillian/src/google.golang.org/genproto/googleapis/rpc/status (from $GOPATH)

trillian_admin_api.pb.go:11:8: cannot find package "google.golang.org/genproto/protobuf/field_mask" in any of:
    /usr/local/go/src/google.golang.org/genproto/protobuf/field_mask (from $GOROOT)
    /Projects/Proj1/trillian/src/google.golang.org/genproto/protobuf/field_mask (from $GOPATH)

去环视输出

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/Projects/Proj1/trillian"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build690359699=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

GOPATHGOROOT已设置但仍无法正常运行命令。尝试安装到家庭和自定义目录更改gopath和goroot无论但仍然没有运气。有任何建议如何解决这个问题?

3 个答案:

答案 0 :(得分:3)

首先在GOROOT和GOPATH环境变量下查找导入的所有包。确保您的包在这些目录下的某个位置。

现在假设 GOPATH 设置为:/ Users / test / Desktop / GoProject

GOROOT :/ usr / local / go(安装了go) 。如果GoProject中的文件具有导入为

的包
import "abc/def/packageName"

那么它应该出现在以下两个地方中的任何一个地方:

<强> /用户/测试/桌面/ GoProject / SRC / ABC / DEF /包/ * 的/ usr /本地/去的/ src目录/ ABC / DEF /包/ *

如果没有,您将收到问题中报告的错误。

这些目录中的文件将第一行显示为

package packageName

声明所有这些文件构成一个包 packageName

答案 1 :(得分:1)

正如官方文件所说:

  

最简单的方法是运行go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

请参阅此处的完整介绍:golang/protobuf installation

答案 2 :(得分:0)

确保具有go SELECT v.start_dt, v.end_dt, t.category, t.item, i.descrip, SUM(t.quantity) FROM transact t JOIN items i ON t.department = i.department AND t.category = i.category AND t.item = i.item JOIN (VALUES (CONVERT(DATE, '2019-03-18'), CONVERT(DATE, '2019-06-01'), (CONVERT(DATE, '2018-03-18'), CONVERT(DATE, '2018-06-01') ) v(start_dt, end_dt) ON t.date_time BETWEEN v.start_dt AND v.end_dt WHERE t.department = '2070' GROUP BY v.start_dt, v.end_dt, t.category, t.item, i.descrip ORDER BY v.start_dt, v.end_dt, t.category, t.item, i.descrip 版本。

较旧的版本不支持模块,因此它们无法下载导致1.11+问题的内容。