Vscode 安裝go環境中遇到的坑!

藍黑蛙發表於2018-01-22

環境安裝

環境windows下安裝go,參考 docs.studygolang.com/doc/install.

然後安裝vscode官方外掛go。需要依賴一些go的外掛,再使用的過程中會提示安裝:Go tools that the Go extension depends on · Microsoft/vscode-go Wiki,但是直接安裝的話是會失敗。

參考這篇文章之後,成功安裝vscode中go的相關外掛 - HackerVirus - 部落格園,安裝成功了。失敗的原因,主要是編譯的時候依賴的庫沒找到,可以自己下載然後移動到相應的路徑下。安然重新啟動vscode自動安裝行了。

遇到問題

但是最後有一個工具 github.com\derekparker\delve\cmd\dlv\, 一直安裝失敗。

PS C:\Go\src> go install .\github.com\derekparker\delve\cmd\dlv\
crypto\tls\cipher_suites.go:18:2: cannot find package "golang_org/x/crypto/chacha20poly1305" in any of:
        C:\Go\src\golang_org\x\crypto\chacha20poly1305 (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\crypto\chacha20poly1305 (from $GOPATH)
crypto\tls\key_agreement.go:20:2: cannot find package "golang_org/x/crypto/curve25519" in any of:
        C:\Go\src\golang_org\x\crypto\curve25519 (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\crypto\curve25519 (from $GOPATH)
net\http\h2_bundle.go:46:2: cannot find package "golang_org/x/net/http2/hpack" in any of:
        C:\Go\src\golang_org\x\net\http2\hpack (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\net\http2\hpack (from $GOPATH)
net\http\h2_bundle.go:47:2: cannot find package "golang_org/x/net/idna" in any of:
        C:\Go\src\golang_org\x\net\idna (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\net\idna (from $GOPATH)
net\http\h2_bundle.go:48:2: cannot find package "golang_org/x/net/lex/httplex" in any of:
        C:\Go\src\golang_org\x\net\lex\httplex (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\net\lex\httplex (from $GOPATH)
net\http\transport.go:32:2: cannot find package "golang_org/x/net/proxy" in any of:
        C:\Go\src\golang_org\x\net\proxy (from $GOROOT)
        C:\Users\talen\go\src\golang_org\x\net\proxy (from $GOPATH)

複製程式碼

一開始以為也是庫沒下載,然後用前面的方式下載到GOPATH,GOROOT下,但是還是會一直出錯。參考了這篇文章:

看到這個才知道,原來crypto這些庫是官方自帶的,最後才發現GOROOT/src路徑下貌似沒有vender,在pkg下面有,於是重新安裝一遍,再次執行就ok了。

The errors that mention "cannot find package" are looking for some packages that are vendored in ~/godev/src/vendor/golang_net/.... However, the vendoring support added in 1.5/1.6 only works when the package is inside the GOPATH or GOROOT. Your godev installation is not (and should not be) inside GOPATH and GOROOT is pointing to your 1.8.1 install.

搜了好多好多的彎路,google幾乎搜不帶多少答案,在github/golang下面搜issue,也沒搜到,windows下幾乎沒有相關的issue。

按F5一鍵除錯:

Vscode 安裝go環境中遇到的坑!

其他參考

go - non-standard import in standard package windows - Stack Overflow:

在中國網路環境下獲取Golang.org上的Golang Packages - Golang中國

標準包是在GOROOT下面,第三方包是在GOPATH下面的: go - Error: Non-standard import "gopkg.in/yaml.v2" in standard package - Stack Overflow

新手求助 為什麼不能載入包 我只是想做一個小爬蟲 程式碼沒有語法錯誤 - Go語言中文網 - Golang中文社群

go get 失敗-CSDN論壇

從這個得知手動安裝包的方式: 下載第三方包 - Golang中國

相關文章