VSCODE gopath与shell中设置的gopath不同
当我尝试导入包时,在VisualStudio代码中遇到了一个非常奇怪的问题VSCODE gopath与shell中设置的gopath不同,go,visual-studio-code,vscode-settings,Go,Visual Studio Code,Vscode Settings,当我尝试导入包时,在VisualStudio代码中遇到了一个非常奇怪的问题 import ( "net/http" "github.com/gorilla/mux" ) 我得到了错误 cannot find package "github.com/gorilla/mux" in any of: /usr/local/go/src/github.com/gorilla/mux (from $GOROOT) /user/chirrut/go/src/
import (
"net/http"
"github.com/gorilla/mux"
)
我得到了错误
cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/user/chirrut/go/src/github.com/gorilla/mux (from $GOPATH)
然而,当我从终端运行GoBuild时,我没有得到任何错误。
还要注意,GOPATH设置为/home/chirrut/go,而不是/user/chirrut/go
我在终端上运行了echo,vscode集成终端都返回了正确的路径
$ echo $GOPATH
/home/chirrut/go
不知何故,VSCode在某处获得的GOPATH值为/user/chirrut/go。有人知道在VS代码中GOPATH变量还从哪里读取吗 这似乎是ms-vscode.go插件的问题,如果我禁用它,问题就会消失。如果我启用它,它就会回来。奇怪的是,我尝试完全卸载它,然后重新安装,问题就消失了
注意:不,自从我第一次设置golang以来,我根本没有对GOPATH进行任何更改 如果启动
code
后更改了路径,请尝试重新启动,如果没有,请查看File>Preferences>Settings
并搜索go。推断并查看是否需要在那里进行任何更改。嗯,我没有对路径进行任何更改,因为我将其保留为默认值。