SublimeText 中的 Gofmt 插件未找到 GOPATH 错误

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


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


杨魅力
浏览 215回答 2
2回答

冉冉说

本文档中提到了在不同操作系统上设置变量的说明 https://github.com/golang/sublime-config/blob/master/docs/user.md我在 macOS 中使用 Sublime3 和 GolangConfig 并遇到了同样的错误。设置以下内容golang.sublime-settings帮助我解决了这个问题。{&nbsp; &nbsp; "PATH": "/Users/suryapandian/go/bin",&nbsp; &nbsp; "GOPATH": "/Users/suryapandian/go"}注:附上下面的图片以查找golang.sublime-settings

慕标琳琳

我意识到我需要将它存在于我的登录shell 中(~/.zprofile在我的例子中),并且现在工作正常。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go