4

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上述内容显然没有被采纳,有什么想法吗?

4

2 回答 2

6

本文档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

在此处输入图像描述

于 2020-07-03T11:22:22.187 回答
4

感谢@lbu 的建议,我意识到我需要它存在于我的登录外壳中(~/.zprofile在我的情况下),它现在工作正常。

于 2019-10-26T05:16:34.310 回答