GOPATH not found 错误来自 SublimeText 中的 Gofmt 插件

GOPATH not found error from the Gofmt plugin within SublimeText

安装 gofmt 软件包后,我在 Sublime Text 中不断收到此错误:

Traceback (most recent call last):
  File "/Users/abrahma/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 257, in run_formatter
    formatter = Formatter(view)
  File "/Users/abrahma/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 166, in __init__
    self.cmds = [Command(cmd, self.view, self.window) for cmd in cmds]
  File "/Users/abrahma/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 166, in <listcomp>
    self.cmds = [Command(cmd, self.view, self.window) for cmd in cmds]
  File "/Users/abrahma/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 77, in __init__
    self.window)
  File "/Users/abrahma/Library/Application Support/Sublime Text 3/Packages/golangconfig/all/golangconfig.py", line 227, in subprocess_info
    raise exception
golangconfig.EnvVarError: The following environment variable is currently unset: GOPATH

我的 `` 文件包含以下内容:

    "env" : {
        "GOPATH" : "/Users/abrahma/git/go",
        "GOROOT" : "/usr/local/Cellar/go/1.12.7/libexec",
    }

(与我终端上 go env 的输出匹配)

我还有一个 golang.sublime-settings 文件,其中包含以下内容:

{
    "env" : {
        "GOPATH" : "/Users/abrahma/git/go",
        "GOROOT" : "/usr/local/Cellar/go/1.12.7/libexec",
    }
}

所以,出于某种原因,上面的 GOPATH 显然没有被选中,有什么想法吗?

感谢@lbu 的建议,我意识到我需要在我的 login shell 中存在这个(~/.zprofile 在我的例子中),现在可以正常使用了。

本文档中提到了在不同 OS 上设置变量的说明 https://github.com/golang/sublime-config/blob/master/docs/user.md

我在 macOs 中使用带有 GolangConfig 的 Sublime3,运行 出现同样的错误。 在 golang.sublime-settings 中设置以下帮助我解决了这个问题。

{
    "PATH": "/Users/suryapandian/go/bin",
    "GOPATH": "/Users/suryapandian/go"
}

注意:附上下面的图片以定位golang.sublime-settings