版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cnwyt/article/details/85003720
golang报错:unrecognized import path “golang.org/x/tour”
由于golang.org
官网无法顺利打开,国内的用户可以使用golang.google.cn
镜像网站来查看一些文档等。
但是在安装x/tour
, x/net
等扩展包的时候,就无能为力了。
除了使用VPN以外,可以使用手动下载代码的方式,下边来介绍一下怎么手动解决的。
手动安装非预装扩展包:
golang 官方在 github
上建立了一个镜像库,直接从github下载镜像代码,放入GOPATH
目录下即可。
直接通过 go get
安装,报错:
$ go get golang.org/x/tour
package golang.org/x/tour:
unrecognized import path "golang.org/x/tour"
(https fetch: Get https://golang.org/x/tour?go-get=1:
dial tcp 216.239.37.1:443: i/o timeout)
$ go get -u golang.org/x/blog
package golang.org/x/blog:
unrecognized import path "golang.org/x/blog"
(https fetch: Get https://golang.org/x/blog?go-get=1:
dial tcp 216.239.37.1:443: i/o timeout)
切换成国内可以打开的 golang.google.cn
网址也不行:
$ go get golang.google.cn/x/tour
package golang.google.cn/x/tour:
unrecognized import path "golang.google.cn/x/tour"
(parse https://golang.google.cn/x/tour?go-get=1:
no go-import meta tags (meta tag golang.org/x/tour did not match
import path golang.google.cn/x/tour))
查看$GOPATH环境变量:
如果没有设置 $GOPATH
环境变量,请参考 “如何设置go环境变量GOPATH?” 。
$ echo $GOPATH
/Users/wangtom/development/gopath
$ cd $GOPATH
$ pwd
/Users/wangtom/development/gopath
首先创建好 src/golang.org/x/
目录:
$ mkdir -p src/golang.org/x/
拉取各个模块的代码:
比如拉取 x/net
代码,直接执行:
$ git clone https://github.com/golang/net.git
可以将Go的各个子包都给下载下来:
$ git clone https://github.com/golang/tour.git
$ git clone https://github.com/golang/net.git
$ git clone https://github.com/golang/blog.git
$ git clone https://github.com/golang/sync.git
$ git clone https://github.com/golang/tools.git
$ git clone https://github.com/golang/lint.git
// ...
每个包的名称如下:
benchmarks — benchmarks to measure Go as it is developed.
blog — blog.golang.org's implementation.
build — build.golang.org's implementation.
crypto — additional cryptography packages.
debug — an experimental debugger for Go.
image — additional imaging packages.
mobile — experimental support for Go on mobile platforms.
net — additional networking packages.
perf — packages and tools for performance measurement, storage, and analysis.
review — a tool for working with Gerrit code reviews.
sync — additional concurrency primitives.
sys — packages for making system calls.
text — packages for working with text.
time — additional time packages.
tools — godoc, goimports, gorename, and other tools.
tour — tour.golang.org's implementation.
exp — experimental and deprecated packages (may change without warning).
VSCode 安装扩展报错:
在 VSCode 中安装go扩展 Go for Visual Studio Code
报错:
gocode:
Error: Command failed: /usr/local/go/bin/go get -u -v github.com/mdempsky/gocode
github.com/mdempsky/gocode (download)
Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
github.com/mdempsky/gocode (download)
Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
问题原因: 该扩展使用了x/tools
,x/lint
等go语言非预装的扩展包,需要先安装.
解决办法: 使用上边介绍的方法,把相关依赖包下载下来即可。
参考链接:
https://blog.csdn.net/cnwyt/article/details/84962807
https://blog.csdn.net/a55569769/article/details/46377267
[END]