gpt4 book ai didi

go - 无法从 $GOROOT 和 $GOPATH 中找到包

转载 作者:IT王子 更新时间:2023-10-29 01:27:27 49 4
gpt4 key购买 nike

我在尝试运行 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,但仍然没有成功。有什么解决办法的建议吗?

最佳答案

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

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

GOROOT :/usr/local/go (安装go的地方).如果您的 GoProject 中的文件有一个导入为

import "abc/def/packageName"

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

/Users/test/Desktop/GoProject/src/abc/def/packageName/*/usr/local/go/src/abc/def/packageName/*

否则,您将收到问题中报告的错误。

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

package packageName

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

关于go - 无法从 $GOROOT 和 $GOPATH 中找到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43325013/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com