简体   繁体   English

VSCODE gopath与shell中设置的GOPATH不同

[英]VSCODE gopath different from GOPATH set in shell

I am encountering a very weird issue on visual studio code when i try to import packages. 当我尝试导入包时,我在Visual Studio代码上遇到一个非常奇怪的问题。

import (
    "net/http"
    "github.com/gorilla/mux"
)

I get the error 我得到错误

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)

however when i run go build from the terminal, I don't get any error. 但是,当我从终端运行go build时,没有任何错误。 also note that the GOPATH is set to /home/chirrut/go instead of /user/chirrut/go I ran echo on terminal, and the vscode integrated terminal and both returns me the correct path. 还要注意,我将GOPATH设置为/ home / chirrut / go而不是/ user / chirrut / go,我在终端上运行了echo,并且集成了vscode的终端都返回了正确的路径。

$ echo $GOPATH
/home/chirrut/go

Somehow, somewhere VSCode is getting the GOPATH value as /user/chirrut/go instead. 不知何故,VSCode在某处获取了GOPATH值为/ user / chirrut / go。 anyone have any idea where else is the GOPATH variable read from in VS Code? 任何人都不知道在VS代码中还从哪里读取GOPATH变量?

This seems like a problem with the ms-vscode.go plugin, if I disable it, the problem go away. 这似乎是ms-vscode.go插件的问题,如果我禁用它,问题就会消失。 and if i enable it, it comes back. 如果我启用它,它就会回来。 Strangely I tried uninstalling it completely, and then reinstall it again, and the problem goes away. 奇怪的是,我尝试将其完全卸载,然后再次重新安装,问题消失了。

Note: No, I did not make any changes to GOPATH at all since i first setup golang. 注意:不,自从我第一次设置golang以来,我根本没有对GOPATH进行任何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM