dsyo9700
2017-05-01 01:25
浏览 134

执行代码构建错误,标准软件包中非标准导入“ fmt”,不允许导入周期

I've been working in go for a little while and this weekend I wanted to try to deploy some server code. When I run go build on some very simple code to test if Go is working I get this error:

can't load package: ($HOME)/go/src/goTest/main.go:4:2: non-standard 
import "fmt" in standard package "goTest"
import cycle not allowed
package goTest
        imports fmt
        imports errors
        imports runtime
        imports runtime/internal/atomic
        imports unsafe
        imports runtime

In my ~/.bashrc I'm running this to set environment variables.

export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

My go workspace is in $HOME/go and my go install is at the default /usr/local/go. Any help is appreciated

main.go

package main

import (
    "fmt"
)

func main() {
    fmt.Println("test")
}

Edit: go version is go1.6 linux/amd64

图片转代码服务由CSDN问答提供 功能建议

我已经工作了一段时间,这个周末我想尝试部署一些服务器代码。 当我在一些非常简单的代码上运行 go build 以测试Go是否正常运行时,出现此错误:

 无法加载包:($  HOME)/go/src/goTest/main.go:4:2:非标准
import标准程序包“ goTest”中的“ fmt” 
导入周期不允许
程序包goTest 
导入fmt 
导入错误
导入 runtime 
导入运行时/内部/原子
导入不安全
导入运行时
   
 
 

在我的〜/ .bashrc中,我正在运行它来设置环境变量。

  export GOPATH = / usr / local / go 
export GOBIN = $ GOPATH / bin 
export PATH = $ PATH:$ GOBIN 
    
 
 

我的go工作区位于 $ HOME / go 中,而go安装位于默认的 / usr / local / go 中。 感谢您的任何帮助

main.go

 包main 
 
import(
“ fmt” 
)
 \  nfunc main(){
 fmt.Println(“ test”)
} 
   
 
 

编辑: go版本 go1.6 linux / amd64

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsl2014 2017-05-01 01:42
    已采纳

    Set $GOPATH, $GOROOT, and $GOBIN correctly. In this case, they should be as follows.

    export GOPATH="$HOME/go"
    export GOROOT="/usr/local/go"
    

    Also, locate the source code correctly. Maybe it should be under $GOPATH/src/github.com/<your id>/<repository name>/

    (If you use newer version of Go (>=1.8), you don't have to set $GOPATH and others. Details here.)

    已采纳该答案
    打赏 评论
  • dongzhong5967 2017-05-01 01:41

    I haven't seen this, but try fixing your paths:

    1) export GOPATH=$HOME/go.

    2) export GOROOT=/usr/local/go.

    3) mkdir -p $GOPATH/src/github.com/nubrozaref/goTest

    4) mv $GOPATH/src/goTest/ $GOPATH/src/github.com/nubrozaref/goTest

    5) if you want: ln -s $GOPATH/src/github.com/nubrozaref/goTest ~/goTest

    打赏 评论

相关推荐 更多相似问题