英文:
Go code building error, non standard import "fmt" in standard package, import cycle not allowed
问题
我已经在Go语言中工作了一段时间,这个周末我想尝试部署一些服务器代码。当我在一些非常简单的代码上运行go build
来测试Go是否正常工作时,我得到了这个错误:
无法加载包:($HOME)/go/src/goTest/main.go:4:2: 非标准导入“fmt”在标准包“goTest”中
不允许循环导入
包goTest
导入fmt
导入errors
导入runtime
导入runtime/internal/atomic
导入unsafe
导入runtime
在我的~/.bashrc文件中,我运行以下命令来设置环境变量。
export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
我的Go工作空间在$HOME/go
中,我的Go安装位于默认路径/usr/local/go
。感谢任何帮助。
main.go
package main
import (
"fmt"
)
func main() {
fmt.Println("test")
}
编辑:go version
是go1.6 linux/amd64
英文:
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
答案1
得分: 2
设置$GOPATH
、$GOROOT
和$GOBIN
正确地。在这种情况下,它们应该如下所示。
export GOPATH="$HOME/go"
export GOROOT="/usr/local/go"
此外,正确地定位源代码。也许它应该位于$GOPATH/src/github.com/<your id>/<repository name>/
下面。
(如果您使用的是更新版本的Go(>=1.8),则不需要设置$GOPATH
和其他变量。详细信息请参阅此处。)
英文:
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.)
答案2
得分: 0
我还没有看到这个,但是尝试修复你的路径:
-
export GOPATH=$HOME/go
。 -
export GOROOT=/usr/local/go
。 -
mkdir -p $GOPATH/src/github.com/nubrozaref/goTest
-
mv $GOPATH/src/goTest/ $GOPATH/src/github.com/nubrozaref/goTest
-
如果你想要的话:
ln -s $GOPATH/src/github.com/nubrozaref/goTest ~/goTest
英文:
I haven't seen this, but try fixing your paths:
-
export GOPATH=$HOME/go
. -
export GOROOT=/usr/local/go
. -
mkdir -p $GOPATH/src/github.com/nubrozaref/goTest
-
mv $GOPATH/src/goTest/ $GOPATH/src/github.com/nubrozaref/goTest
-
if you want:
ln -s $GOPATH/src/github.com/nubrozaref/goTest ~/goTest
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论