I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

huangapple go评论84阅读模式
英文:

I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

问题

我在Windows上使用IntelliJ IDEA作为Golang的IDE,并且系统环境已经设置了GOPATH,但是IDEA无法加载$GOPATH。

我使用go get github.com/astaxie/beego命令安装了这个包,但是在IDEA中无法导入这个库。

我已经按照以下方式将这个包添加到项目的结构中:

I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

并且选择了项目的Go SDK为“Go sdk go1.1.1 windows/amd64 ”,如下图所示:
I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

我该如何在IDEA中设置GOPATH?

英文:

I use IntelliJ IDEA as golang IDE in Windows , and system environment have already set GOPATH,but IDEA can't load $GOPATH.

I use go get github.com/astaxie/beego, this package is installed correctly, but in IDEA can't import this library.

I have added this package in project's structure in this way:

I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

and this project's choice “Go sdk go1.1.1 windows/amd64 ”like
I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

how can I set GOPATH in idea?

答案1

得分: 50

更新(2017-10-22)

根据新版本Gogland(EAP 16)的发布说明,相应的Go插件现在只能与IntelliJ IDEA Ultimate一起使用。这遵循了通过IntelliJ IDEA Ultimate插件或作为独立IDE(如PyCharm,Webstorm或本例中的Goland)提供对不同语言的支持的模式。

有关更多详细信息,请参阅相关博客文章

更新(2017-04-24)

作为最终解决OP问题的替代方案,我想推荐专门用于Go开发的新IDE JetBrains Gogland。设置非常简单,但如果您遇到困难,已经提供了有用的文档。

查看Gogland,可能适合您。

还有一个官方插件,其中“包含了您在Gogland中找到的一切”。

如果您想知道这个新插件与旧的go-lang-idea-plugin之间的区别是什么,请查看FAQ文章中的解释。

原始答案

背景信息

在OS X Mavericks上,通过Macports安装了Go。使用IntelliJ IDEA的Go插件版本0.9.15。

问题

我希望使IDE理解导入并为我在GOPATH中安装的任何包提供自动完成。(我开始使用Revel创建应用程序,但缺少自动完成...)

解决方案

这是我所做的:

  • 配置Go SDK(在菜单中:View > Open Library Settings > Platform Settings > SDKs)。
  • 打开要设置的Go SDK的“Classpath”选项卡。
  • 添加一个新项目,选择您的$GOPATH中的“src”目录。
  • 点击“应用”或“确定”。
  • (不起作用?!?,抱怨,头痛...)
  • 在菜单中:File > Invalidate Caches / Restart...
  • 点击“使缓存无效并重新启动”。
  • 成功!

希望这可能是您正在寻找的!

英文:

Update (2017-10-22)

According to the release notes of the new version of Gogland (EAP 16), the corresponding Go plugin can only be used with IntelliJ IDEA Ultimate from now on. This follows the pattern of providing support for different languages either via a plugin for IntelliJ IDEA Ultimate, or as a standalone IDE, such as PyCharm, Webstorm, or in this case, Goland.

For more details see the related blog post.

Update (2017-04-24)

As an alternative solution that ultimately deals with the OP's problem, I would like to recommend the new IDE specifically for Go development, JetBrains Gogland. The setup is pretty much effortless, but in case you would have difficulties, there is already heplful documentation provided.

Check Gogland, might work for you.

There is also an official plugin that "has everything you could find in Gogland".

In case you are wondering what could be the difference between this new plugin, and the old go-lang-idea-plugin, check the FAQ article with the explanation.

Original answer

Background info

On OS X Mavericks, Go installed via Macports. Using Go plugin version 0.9.15 with IntelliJ IDEA.

Problem

I wanted to make the IDE understand the imports and provide autocomplete for any package I have installed in GOPATH. (I started creating an app using Revel and were missing the autocomplete...)

Solution

Here is what I did:

  • Configure the Go SDK (In menu: View > Open Library Settings > Platform Settings > SDKs).
  • Open the "Classpath" tab of the Go SDK you want to set up.
  • Add a new item, select the 'src' directory in your $GOPATH.
  • Click 'Apply' or 'OK'.
  • (not working!?!?, grumble, headache...)
  • In menu: File > Invalidate Caches / Restart...
  • Click 'Invalidate and Restart'.
  • WIN!

Hope this might be what you were looking for!

答案2

得分: 18

这是您在IntelliJ 2016中设置GOPATH的位置(在我的情况下,我的GOPATH是/development/workspace/golang)

英文:

This is where you set GOPATH in IntelliJ 2016 (in my case my GOPATH is /development/workspace/golang)

I use IntelliJ IDEA as golang IDE, and system environment have already set GOPATH,But IDEA can't load it

答案3

得分: 4

尝试使用最新版本的插件。自0.9.15版本发布以来,它应该工作得更好。

如果有任何问题,请随时帮助我们或报告遇到的任何错误。

英文:

Try the latest version of the plugin. It should work better since 0.9.15 release.

And feel free to help us out or report any bugs you encounter.

答案4

得分: 3

IDEA插件对于Go不理解由Go约定定义的GOPATH,它只使用由SDK确定的GOROOT。最好的解决方法是在GOROOT中创建符号链接到GOPATH中的包:

$GOPATH/src/github.com       <--  $GOROOT/src/pkg/github.com
$GOPATH/src/code.google.com  <--  $GOROOT/src/pkg/code.google.com
...等等

在Windows中也应该是可行的。

英文:

IDEA plugin for Go does not understand GOPATH as it is defined by Go conventions, it uses only GOROOT, which is determined from SDK. The best workaround is to make symbolic links in GOROOT to packages in GOPATH:

$GOPATH/src/github.com       <--  $GOROOT/src/pkg/github.com
$GOPATH/src/code.google.com  <--  $GOROOT/src/pkg/code.google.com
... etc

It should be possible to do in Windows too.

答案5

得分: 1

我不使用IntelliJ,但是我在Eclipse中遇到了类似的问题。
我可能做错了什么,但是Eclipse不能自动识别GOPATH环境变量。

我所做的是手动在Go设置中添加一个我正在使用的库的条目。
例如,它看起来像/somewhere/in/your/hd/github.com/astaxie/beego。
请注意,您必须指定库的基本目录,而不是/src或/pkg文件夹。

希望这可以帮到你。

英文:

I don't use IntelliJ, but i have a similar issue with Eclipse.
I'm probably doing something wrong but Eclipse does not recognize the GOPATH env variable by itself.

What I do is adding manually to the Go settings an entry to the library i am using.
For example it would looks like /somewhere/in/your/hd/github.com/astaxie/beego.
Note that you have to specify the base directory of your library, not the /src or /pkg folder.

Hope this helps.

答案6

得分: 1

在您的系统设置中,请确保所有这些环境变量设置如下:

GOROOT=C:\Go
GOBIN=%GOPATH%\bin
PATH=%PATH%;c:\go\bin;%GOBIN%

(如果您已经在c:\Go中安装了Go)

在您的用户文件夹中创建一个名为goplayground的Go目录
创建另一个环境变量,指向该目录

GOPATH=C:\Users\YOUR_USENAME\goplayground

就是这样。
现在,IntelliJ IDEA Go插件应该可以正常工作了。

英文:

In your system setting make sure all these enviroment variables are set in this way

GOROOT=C:\Go
GOBIN=%GOPATH%\bin
PATH=%PATH%;c:\go\bin;%GOBIN%

(If you have installed Go in c:\Go)

In your user folder create a directory for Go, named for example goplayground
Create another environment variable that points to this directory

GOPATH=C:\Users\YOUR_USENAME\goplayground

That's all.
Now IntelliJ IDEA Go plugin should work correctly.

huangapple
  • 本文由 发表于 2013年7月21日 17:57:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/17771091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定