go - 使用go mod时出现 'ambiguous import'怎么解决?

标签 go

我正在尝试在我的 Windows 机器上运行 go-ethereum@v1.0.0。

我的工作:

cd G:\go
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum/cmd/geth
git checkout tags/v1.0.0 -b v1.0.0
go mod init github.com/ethereum/go-ethereum/cmd/geth
go run .

希望go mod可以帮我安装所有模块,但是遇到错误:

package github.com/ethereum/go-ethereum/cmd/geth: unknown import path "github.com/ethereum/go-ethereum/cmd/geth": ambiguous import: found github.com/ethereum/go-ethereum/cmd/geth in multiple modules:
        github.com/ethereum/go-ethereum/cmd/geth (G:\go\go-ethereum\cmd\geth)
        github.com/ethereum/go-ethereum v1.8.23 (G:\GOPATH\pkg\mod\github.com\ethereum\go-ethereum@v1.8.23\cmd\geth)

我认为那是因为 cmd/geth 存在于 $GOPATH 和 $PWD 中。怎么解决才能运行成功?

PS: 我希望它使用 $PWD 以便我可以更改它。

最佳答案

如果你想geth,就这样做。我这样做了。

cd $GOPATH/src
git clone https://github.com/ethereum/go-ethereum.git
cd $GOPATH/src/github.com/ethereum/go-ethereum
git checkout tags/v1.0.0 -b v1.0.0
go install github.com/ethereum/go-ethereum/cmd/geth
ls $GOPATH/bin/geth

关于go - 使用go mod时出现 'ambiguous import'怎么解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371508/

相关文章:

database - 在 for 循环中使用 db 连接时内存泄漏

go - 如何在 Golang 中将全角数字字符转换为 Ascii?

Golang 避免代码重复

带证书的 Golang Opc UA 客户端实现

go - 如果我的 key 都被命名为 "Key",我如何从 BSON 获取 JSON?

go - 在go中使用字符串通过名称实例化结构

Go: 无效操作 - 类型 *map[key]value 不支持索引

go - 类型断言会改变go中的值吗?

去模块 : How do you lock in a specific version that won't get overridden with `go get -u` ?

go - 有没有办法在 Go 中组合可能失败的操作?