无法导入 github.com/gorilla/mux(在任何一个中都找不到包“github.com/gorilla/mux”) C:\Program Files\Go\src\github.com\gorilla\mux (来自 $GOROOT) C:\Users\lenovo\go\src\github.com\gorilla\mux (来自 $GOPATH))compilerBrokenImport
我已经使用 cmd“go get github.com/gorilla/mux”安装了 gorilla mux,但出现此错误。
看起来您没有在“go get”之前运行“go mod init”。
在cmd中,试试这个:
cd [the dir of your source code]
go mod init
go get github.com/gorilla/mux
欲了解更多信息,请运行:
go help mod
我遇到了具有相同症状的问题: 如果您在 main.go 文件中只导入“gorilla/mux”而不是“github.com/gorilla/mux”,编译器将无法合并正确的包。
代替:
import (
"gorilla/mux"
// other imports omitted for brevity
)
尝试:
import (
"github.com/gorilla/mux"
// other imports omitted for brevity
)