GOPATH not found error from the Gofmt plugin within SublimeText
Asked Answered
B

2

6

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?

Breathtaking answered 25/10, 2019 at 22:48 Comment(3)
is GOPATH set in your .profile file?Theorist
I do have it set in my .zshrcBreathtaking
(and that made me realize ... I needed it in my .zprofile -- done, works!)Breathtaking
B
5

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.

Breathtaking answered 26/10, 2019 at 5:16 Comment(3)
I don't have a ~/.zprofile... Do i need to create it and add export GOPATH=$(go env GOPATH)?Ogilvy
Lol, had this error again, in a new place, and ... found my old question. Sheesh, I didn't really learn after all :-)Breathtaking
@Ogilvy sorry I never answered your question (two years ago!) but ...yes.Breathtaking
S
15

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

Shelbashelbi answered 3/7, 2020 at 11:22 Comment(2)
this fixed it for me! what a helpful and thorough answer, thank you!Makell
thank you. glad i could be of helpShelbashelbi
B
5

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.

Breathtaking answered 26/10, 2019 at 5:16 Comment(3)
I don't have a ~/.zprofile... Do i need to create it and add export GOPATH=$(go env GOPATH)?Ogilvy
Lol, had this error again, in a new place, and ... found my old question. Sheesh, I didn't really learn after all :-)Breathtaking
@Ogilvy sorry I never answered your question (two years ago!) but ...yes.Breathtaking

© 2022 - 2024 — McMap. All rights reserved.