英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论