无法运行’/usr/local/go/bin/go env’。配置更改可能未正确应用。

huangapple go评论116阅读模式
英文:

Failed to run '/usr/local/go/bin/go env. The config change may not be applied correctly

问题

每当我尝试在 Visual Studio Code 中保存一个 Go 文件时,我都会弹出一个窗口,显示“Failed to run '/usr/local/go/bin/go env. The config change may not be applied correctly.”。此外,没有 Go 的智能感知、代码导航和代码编辑支持。

英文:

Whenever i try save a go file inside vc code i get this pop up Failed to run '/usr/local/go/bin/go env. The config change may not be applied correctly. . Also there is any no go intelliSense, code navigation, and code editing support.

答案1

得分: 1

我猜你正在使用Go模块,并且在项目目录中有go.mod文件。在这种情况下,在VsCode中,打开首选项。在扩展下,选择Go。取消勾选“从工作区根目录推断GOPATH”的复选框,分别对“用户”和“工作区”进行操作。
关闭所有终端和VsCode实例,然后重新启动VsCode。它应该不再显示错误,并提示安装Go工具的消息。否则,你可以从VsCode手动安装Go工具(按下crtl/cmd + shift + P),这将恢复智能感知和代码检查。

英文:

I guess, you are using go modules and have go.mod file inside project directory. In this case, inside VsCode, go to preferences. Under extensions, select Go. Untick checkbox labelled "Infer GOPATH from the workspace root." for both "User" and "Workspace".
Close all terminal and VsCode instance, and restart VsCode. It should no longer display the error, and prompt message to install Go Tools. Else you can manually install go tools from VsCode (pressing crtl/cmd + shift + P), which will bring back intellisense and linting.

答案2

得分: 0

我已经解决了这个问题。解决方法是创建一个新的Golang项目,并将所有所需的逻辑文件从旧项目移动到新项目中,这样就可以解决问题了。问题出在.mod和.sum文件上。这是一个我在另一台笔记本电脑上创建的旧项目,那台电脑上安装的是基于Ubuntu的Feren操作系统。当我将这个项目移动到我的新笔记本电脑上,那台电脑上安装的是基于Ubuntu的Zorin操作系统时,就出现了问题。所以在尝试了很多解决方案之后,我只是创建了一个新的Golang项目,并将所有所需的文件移动过去,问题就解决了。

英文:

I have solved this issue. The solution is that, create a new Golang project and move all the required logic files from older project to newer project and it will work. The problem is with .mod and .sum files. It is a older project that i have created on my other laptop that has Ubuntu based Feren OS. When I moved this project to my newer laptop that has Ubuntu based Zorin OS. It creates problem. So after trying lots of solution, I just created a new Golang project and moves all the required files and it works.

答案3

得分: -1

如果你正在使用Mac OS并且通过Homebrew安装了Go,请将以下内容添加到你的settings.json文件中:

"go.goroot": "/opt/homebrew/opt/go/libexec"

路径可能会有所不同,请通过export GOROOT="$(brew --prefix golang)/libexec"进行检查。

另外,请参考在Mac上安装Go

英文:

In case you are using Mac OS and installed Go via homebrew add

"go.goroot": "/opt/homebrew/opt/go/libexec"

To your settings.json file. The path may be different. Check it via export GOROOT="$(brew --prefix golang)/libexec".

Also see install go on mac

huangapple
  • 本文由 发表于 2022年3月13日 20:38:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/71456823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定