dsyo9700 2017-05-01 01:25
浏览 156
已采纳

执行代码构建错误,标准软件包中非标准导入“ 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

  • 写回答

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.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档