小部分的错误,我得到后,试图运行去构建命令
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)
字符串
Go env输出
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"
型GOPATH
和GOROOT
已设置,但仍然无法在没有错误的情况下运行命令。尝试安装到家庭和自定义目录,改变gopath和goroot不管,但仍然没有运气。有什么建议可以解决这个问题吗?
6条答案
按热度按时间ux6nzvsh1#
所有导入的包首先在GOROOT和GOPATH环境变量下查找。确保您的软件包位于这些目录下的某个位置。
现在假设GOPATH设置为:/Users/test/Desktop/GoProject
字符串
那么它应该出现在以下两个位置中的任何一个:
/Users/test/Desktop/GoProject/src/abc/def/packageName/* /usr/local/go/src/abc/def/packageName/*
如果没有,您将得到问题中报告的错误。
这些目录中的文件的第一行为
型
声明所有这些文件构成一个包packageName
4zcjmb1e2#
正如官方文件所说:
最简单的方法是运行
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
。在这里查看完整的介绍:golang/protobuf安装。
sd2nnvve3#
确保有一个版本的go
1.11+
。旧版本不支持模块,因此无法下载所需的内容,导致
Can't find package from $GOROOT and $GOPATH
问题。0sgqnhkj4#
我在终端中安装了 go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
然后做了一个 go mod init example.com/filename,这创建了一个go mod文件,并为我删除了错误。
cpjpxq1n5#
我使用Go 1.20,我的项目在~/DSBSystems。
下面是我运行的步骤:
2hh7jdfx6#
转到您的main.go目录并运行
go get -u .
,它将下载基于go.mod文件的代码所需的所有包