首页 > 解决方案 > 强制重新下载/完全清洁环境

问题描述

首先,我没有使用 go 的经验,我只是想从 github 构建一个项目。

我的问题:当我go build在一个克隆的 go 项目中使用时,我得到了一堆这样的错误:

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也会产生同样的错误。我也尝试过重新安装 go with pacman -S 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 认为包应该仍然存在?

标签: gobuild

解决方案


在阅读回复评论后,我偶然发现了go mod verify似乎解决了我的问题的命令。


推荐阅读