Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GOPATH not found error from the Gofmt plugin within SublimeText

I keep getting this error within Sublime Text, after installing the gofmt package:

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

My `` file has the following:

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

(which matches the output of go env on my terminal)

I also have a golang.sublime-settings file with the following:

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

So, for some reason, the GOPATH above clearly isn't getting picked up, any ideas why?

like image 259
agam Avatar asked Dec 23 '22 20:12

agam


2 Answers

Instructions for setting the variables on different OS are mentioned in this doc https://github.com/golang/sublime-config/blob/master/docs/user.md

I use Sublime3 with GolangConfig in macOs and ran into the same error. Setting the below in golang.sublime-settings helped me fix the issue.

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

Note: Attaching pic below to locate golang.sublime-settings

enter image description here

like image 170
Luna Lovegood Avatar answered Apr 27 '23 07:04

Luna Lovegood


Thanks to the suggestion by @lbu, I realized that I needed this to exist in my login shell (~/.zprofile in my case), and it works fine now.

like image 22
agam Avatar answered Apr 27 '23 06:04

agam