登录
首页 >  Golang >  Go问答

Gofmt 插件在 SublimeText 中无法识别 GOPATH 的问题

来源:stackoverflow

时间:2024-02-25 08:09:25 348浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《Gofmt 插件在 SublimeText 中无法识别 GOPATH 的问题》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

问题内容

安装 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 
    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 的建议,我意识到我需要将其存在于我的登录 shell 中(在我的例子中是 ~/.zprofile),并且现在工作正常。

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

我在 macos 中使用 sublime3 和 golangconfig 并遇到了相同的错误。 在 golang.sublime-settings 中设置以下内容帮助我解决了问题。

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

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

本篇关于《Gofmt 插件在 SublimeText 中无法识别 GOPATH 的问题》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>