在 Mac OS X 下,我执行了 brew install go。我还从这里下载了 Go IntelliJ IDE
http://go-ide.com/2011/08/09/goide_release_1_0_darwin.html
以下程序在命令行中编译和运行良好,但如果我使用 GO IntelliJ IDE,它会给出错误:
can't find import: math/rand
导入时间似乎没问题,但 Duration 和 time.Millisecond 未定义。如果我删除这些东西并只运行“Hello World 版本”,程序编译并运行良好。
/**
* Created by IntelliJ IDEA.
* User: idf
* Date: 4/2/14
* Time: 1:59 PM
* To change this template use File | Settings | File Templates.
*/
package main
import (
"fmt"
"math/rand" /* causes problems */
"time"
)
func main() {
sleep := time.Duration(200) /* error: undefined: time.Duration */
time.Sleep(sleep * time.Millisecond) /* error: undefined: time.Millisecond */
rand.Intn(1000)
fmt.Println("Hello World")
}
最佳答案
已更新:
你需要添加你的 GOROOT 和 GOPATH:
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md
我运行的确切命令(显然,您的 GOPATH 和 GOROOT 会有所不同):
launchctl setenv GOPATH /Users/wfreeman/gocode
launchctl setenv GOROOT /Users/wfreeman/go1.2
关于intellij-idea - Go 从命令行工作,但不是从 IntelliJ Idea Go,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22821000/