12

I am using PyCharm 3.1.1 and I have installed the Go plugin for IntelliJ Idea. I did export GOROOT=$(go env GOROOT) to prevent PyCharm from complaining about missing GOROOT environment variable.

Now I was able to create a sample project, but the run command complains:

Error running untitled1.go: No Go Sdk defined for this project

On other sites I found that I should do something like:

Go to the File -> Project Structure and configure Go SDK by clicking + button and selecting /usr/lib/go/ folder.

But I don't have File -> Project Structure menu item.

How to make PyCharm work with the Go plugin?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
warvariuc
  • 57,116
  • 41
  • 173
  • 227
  • 1
    Personally I keep a separate IDEA for the golang plugin, and not mix PyCharm with the Go plugin. Do you have a reason to keep them together other than saving disk space? – Not_a_Golfer Apr 08 '14 at 07:53
  • I use PyCharm for Python development. It would be nice to have everything in one place. If it's not possible - I'll use a separate IDEA – warvariuc Apr 08 '14 at 08:01
  • You could try to start with a fresh IDEA and then add both Python as a plugin and Go as a plugin. – Not_a_Golfer Apr 08 '14 at 08:03
  • I have a license for PyCharm, and I think the community version does not have all the features. – warvariuc Apr 08 '14 at 08:11
  • What it lacks is mainly framework integration (django, etc). Code analysis, debugging, completion etc - all work perfectly. I used to have the commercial version and I found that I don't really need any of the features the community version is missing so I didn't renew my license. – Not_a_Golfer Apr 08 '14 at 09:00
  • Thanks for the hint! I will try to install IDEA with Python and Go plugins – warvariuc Apr 08 '14 at 09:04

5 Answers5

3

You can get most of the way there with External Tools. There is no way to replace the 'Run' button until the next version of the plug-in, per Issue #728.

To set up your external tools, go to PyCharm -> Preferences (command+,) -> Tools -> External Tools -> +

Fill in the form: enter image description here

Hit OK. Use it from the menus: enter image description here

Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
2

You can achieve it now with a Version 2016.1 or higher. I will give a complete guide, so the first steps would not be relevant for you. Also I write it using MacOS, so some names might be different. Go to

Preferences -> Plugins -> Browse Repositories -> Manage repositories and insert https://plugins.jetbrains.com/plugins/alpha/5047 which is the plugin behind this repo (maintained by IntelliJ). Install that plugin.

After plugin is installed, create a .go file. When you open it you will see a popup go project sdk is not defined. Click on it and select your /usr/local/go path.

A couple of helpful links:

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
1

Please use the latest release from Github releases https://github.com/go-lang-plugin-org/go-lang-idea-plugin/releases. It supports PyCharm 4.0.5+.

dlsniper
  • 7,188
  • 1
  • 35
  • 44
0

If you are an IntelliJ fan, you can edit and run Go using goland editor (Notice, this is not a Go plugin added to PyCharm but a different editor).

For installation on Ubontu: sudo snap install goland --classic , or visit there website https://www.jetbrains.com/help/go/install-and-set-up-product.html

David Wer
  • 368
  • 3
  • 12
-3

If you're running on OS X, you'll have to use the launchctl setenv command to set the GOROOT environment variable, so it's available system wide, which includes launching applications via the GUI

launchctl setenv GOROOT $(go env GOROOT)

To check it's set

launchctl getenv GOROOT

For the values to persist across reboots, you'll need to edit (or create) /etc/launchd.conf:

setenv GOROOT [path]

See this answer for more information of the format of this file. Note that you won't be able to call $(go env GOROOT) within launchd.conf

Community
  • 1
  • 1
Stuart Carnie
  • 5,458
  • 1
  • 29
  • 27
  • 2
    The question is not about about `GOROOT` environment variable. It's about PyCharm vs IDEA – warvariuc May 08 '14 at 04:21
  • Why then does is the last statement in the article "How to make PyCharm work with Google Go language plugin?" and the title of the question is "Google Go language plugin with PyCharm" – Stuart Carnie Jul 15 '14 at 06:42
  • The question was not about environment variables. It was how to set up Go SDK in PyCharm. – warvariuc Jul 15 '14 at 06:59