noonat / sublime-gofmt

Sublime plugin to run gofmt (or goimports, or whatever you want).
MIT License
28 stars 6 forks source link

GOPATH not set error #16

Open karl-gustav opened 4 years ago

karl-gustav commented 4 years ago

Got this error after installing this plugin with package control:

  File "/Users/some_user/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 257, in run_formatter
    formatter = Formatter(view)
  File "/Users/some_user/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/some_user/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/some_user/Library/Application Support/Sublime Text 3/Installed Packages/Gofmt.sublime-package/gofmt.py", line 77, in __init__
    self.window)
  File "/Users/some_user/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

The ENV variable is set if I open up a terminal, but I'm guessing this is looking some where else for that variable...

mm-git01 commented 4 years ago

did anyone find a solution for this,even though everything is set properly this error continues to pop up its is quite annoying.

ghost commented 4 years ago

Has anyone found the solution? I have them properly set under go env and also tried making a json user setting but nothing

{
    "env":
    {
        "GOPATH": "/home/user/go",
    }
}
JohnDDuncanIII commented 4 years ago

I could only get this to work by going to the Golang Config package settings and manually setting my PATH and GOPATH there.

golang.sublime-settings

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

https://github.com/golang/sublime-config/blob/master/docs/user.md#global-sublime-text-settings

Screen Shot 2020-08-24 at 12 23 24 AM

What's weird is that I did not need to manually set the PATH, GOPATH, nor GOROOT to get SublimeLinter-golint working. Not exactly sure why that is the case.


from the author:

I use golangconfig to run the go binaries. It supports overriding the PATH it uses, and has examples in the user documentation. As its intent is to normalize configuration across Golang packages for Sublime, I’d rather not deviate from its established way of doing things. Could you take a look at the docs and see if that gets things working?

https://github.com/noonat/sublime-gofmt/issues/5#issuecomment-335198104

DCTmaybe1201 commented 3 years ago

I got the same problem when use sublime text 4 and install package https://packagecontrol.io/packages/Gofmt on MacOS

Use command which go in your terminal to get the GOPATH. Set them in golang.sublime-settings

{
    "PATH": "/usr/local/bin/go/bin",
    "GOPATH": "/usr/local/bin/go"
}

It's done.

salekh commented 2 years ago

I can confirm that the same issue exists on Ubuntu 22.04 as well, and the fix works there too. By default, the golang.sublime-settings file will be located under ~/.config/sublime-text/Packages/User

Nicolas-ggd commented 2 months ago

I got the same problem when use sublime text 4 and install package https://packagecontrol.io/packages/Gofmt on MacOS

Use command which go in your terminal to get the GOPATH. Set them in golang.sublime-settings

{
    "PATH": "/usr/local/bin/go/bin",
    "GOPATH": "/usr/local/bin/go"
}

It's done.

Duuuuude, thank you a lot <3 you save my life