首先,我没有使用 go 的经验,我只是想从 github 构建一个项目。
我的问题:当我在一个克隆的 go 项目中使用 go build
时,我得到了一堆这样的错误:
transform.go:28:2: cannot find package "github.com/disintegration/imaging" in any of:
/usr/lib/go/src/github.com/disintegration/imaging (from $GOROOT)
/home/marcus/go/src/github.com/disintegration/imaging (from $GOPATH)
imageproxy.go:34:2: cannot find package "github.com/gregjones/httpcache" in any of:
/usr/lib/go/src/github.com/gregjones/httpcache (from $GOROOT)
/home/marcus/go/src/github.com/gregjones/httpcache (from $GOPATH)
transform.go:29:2: cannot find package "github.com/muesli/smartcrop" in any of:
/usr/lib/go/src/github.com/muesli/smartcrop (from $GOROOT)
/home/marcus/go/src/github.com/muesli/smartcrop (from $GOPATH)
发生了什么:我破坏了一切,因为我开始删除随机目录,希望能解决我遇到的另一个问题。我删除了我的 ~/go
目录和 ~/.cache/go-build
目录。
我尝试过的:到目前为止,除了导致问题的删除之外,我还尝试过 go clean -cache -modcache
;添加 -r
标志会产生与上述相同的错误。 go build -a
也会产生相同的错误。我还尝试使用 pacman -S go
重新安装 go。
我的 go env
是:
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/marcus/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/marcus/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build315222728=/tmp/go-build -gno-record-gcc-switches"
我知道我做的事情出乎意料,但我很惊讶 Go 在这里挣扎。我怎样才能让 Go 意识到这些包不存在并且它应该通过下载它们来解决这个问题?或者,我如何清理我的环境以删除任何仍然存在的工件,这些工件让 Go 认为包应该仍然存在?
最佳答案
阅读完评论后,我偶然发现了 go mod verify
命令,它似乎解决了我的问题。
关于go - 强制重新下载/完全清洁环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52707474/