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

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上