Intellij Golang 无法找到模块。

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

Intellij Golang cannot find a module

问题

我正在使用IntelliJ的Golang插件,在为模块和项目设置了GO SDK之后。我尝试编辑项目的配置。当我点击编辑配置时,在模块下拉框中,它显示没有模块。似乎配置无法找到该模块。我是否漏掉了什么?为了使Go SDK在Intellij中工作,我已经执行了以下命令:

mkdir /usr/lib/go/bin

ln -s /usr/bin/go /usr/lib/go/bin/go

ln -s /usr/bin/godoc /usr/lib/go/bin/godoc

ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt

英文:

I am using Golang plugin for IntelliJ, after set the GO Sdk for the module and project. I tried to edit configuration for the project. When I click the edit configuration, in module dropdown box, it shows no module. it seems the configuration cannot find the module. Anything that I missed? I have issue the following command in order to make Go SDK work in Intellij.

      # mkdir /usr/lib/go/bin
      # ln -s /usr/bin/go    /usr/lib/go/bin/go
      # ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
      # ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt

答案1

得分: 3

在最新版本的IntelliJ中(这里是Ultimate 2019.1.3的截图),你可以在Preferences(首选项)-> Language & Frameworks(语言和框架)-> Go(Go语言)-> GOROOT/GOPATH(Go根目录/Go路径)中找到GOROOT和GOPATH。

  1. 在你的系统中安装Golang(我使用了brew):

    自从OSX ElCapitan以来,OSX禁止访问/bin目录,这会导致使用默认设置编译项目时出现问题,并出现以下错误:

    无法运行程序/bin/go(在目录/Users/XXX/go/src/YYY/ZZZ/service中):错误=2,没有该文件或目录

    因此,可以通过更新GO首选项来解决这个问题。

  2. 打开IntelliJ和你的Go项目,并在项目中更新GOROOT。

    Intellij Golang 无法找到模块。

  3. 如果你有自定义的GOPATH目录,请同时更新它。

    Intellij Golang 无法找到模块。

  4. 点击运行你的Go程序。

英文:

In the recent version of IntelliJ (here is screenshot from Ultimate 2019.1.3) you can find the GOROOT and GOPATH in Preferences -> Language & Frameworks -> Go -> GOROOT/GOPATH.

  1. Install to Golang in your system (I used brew):

    > Since OSX ElCapitan, the OSX forbid access to /bin directory, which would cause problems with compiling the project with the default settings and having error like:
    >
    > Cannot run program "/bin/go" (in directory "/Users/XXX/go/src/YYY/ZZZ/service"): error=2, No such file or directory
    >
    > So this should be solved by updating GO preferences.

  2. Open IntelliJ and your go project and update GOROOT in your project

    Intellij Golang 无法找到模块。

  3. If you have a custom directory of GOPATH do update it as well.

    Intellij Golang 无法找到模块。

  4. Click to run your go program.

答案2

得分: 2

这对我有效:

  1. 关闭 GoLand。
  2. 导航到项目根目录,备份并删除 .idea 目录。
  3. 再次打开 IDE。

来源:https://youtrack.jetbrains.com/issue/GO-11854

英文:

this works for me:

  1. Close GoLand.
  2. Navigate to the project root, backup and delete .idea
    directory.
  3. Open the IDE again.

by https://youtrack.jetbrains.com/issue/GO-11854

答案3

得分: 1

请尝试使用该插件的最新版本,看看问题是否仍然存在。

请注意,您不需要链接任何内容,只需设置您的$GOROOT环境变量(或者不设置,如本文中所述),以及您的$GOPATH

英文:

Try the recent latest releases of that plugin, to see if the issue persists.

Note that you shouldn't have to link anything, just set your $GOROOT environment variable (or not, as mentioned in this article), and your $GOPATH.

huangapple
  • 本文由 发表于 2014年10月27日 10:54:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/26580525.html
匿名

发表评论

匿名网友

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

确定