Go安装:“无法加载包”(即使设置了GOPATH)

huangapple go评论84阅读模式
英文:

Go install: “Can't load package” (even though GOPATH is set)

问题

我刚刚开始学习Go编程语言,并使用网站上的Windows安装程序安装了Go。我通过使用go run hello.go进行了安装测试,一切正常。但是当我尝试构建我的第一个程序时出现了问题:

$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello

在该目录下,我有一个简单的hello.go程序:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world.\n")
}

当我尝试构建和安装时出现问题:

$ go install hello
无法加载包:找不到任何位置的包“hello”:
    C:\Go\src\hello(来自$GOROOT)
    \cygdrive\c\Users\Paul\Documents\Home\go\src\hello(来自$GOPATH)
英文:

I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:

$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello

Inside that directory I have a simple hello.go program:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world.\n")
}

The problem comes when I try to build and install:

$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
    C:\Go\src\hello (from $GOROOT)
    \cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)

答案1

得分: 3

GOPATH 环境变量必须包含有效的路径。

\cygdrive\c\Users\Paul\Documents\Home\go\src\hello 不是 Windows 上的有效路径。

尝试将 GOPATH 设置为 c:\Users\Paul\Documents\Home\go

英文:

GOPATH environment variable must contain valid path.

\cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.

Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

huangapple
  • 本文由 发表于 2015年1月7日 07:40:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/27809176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定