Golang包导入 – 找不到包

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

Golang package imports - cannot find package

问题

这是我第一次在这里提问,无论如何,我想知道为什么它说找不到包,即使github.com/JohnDoe/temperature/conversion/conv$GOPATH中。

[johndoe@johndoe temperature]$ go run main.go
main.go:5:2: 找不到包"github.com/JohnDoe/temperature/conversion/conv",在以下任何位置都找不到:
/usr/local/go/src/github.com/JohnDoe/temperature/conversion/conv (来自$GOROOT)
/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion/conv (来自$GOPATH)

更多细节:

[johndoe@johndoe conversion]$ pwd
/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion

[johndoe@johndoe conversion]$ ls
conv.go

你有什么想法?

英文:

This is my first time asking a question here, anyway, I am wondering why it says it can't find the package, even though github.com/JohnDoe/temperature/conversion/conv is inside the $GOPATH

[johndoe@johndoe temperature]$ go run main.go
main.go:5:2: cannot find package "github.com/JohnDoe/temperature/conversion/conv" in any of:
	/usr/local/go/src/github.com/JohnDoe/temperature/conversion/conv (from $GOROOT)
	/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion/conv (from $GOPATH)

more details:

[johndoe@johndoe conversion]$ pwd
/home/johndoe/Workspace/Go/src/github.com/JohnDoe/temperature/conversion

[johndoe@johndoe conversion]$ ls
conv.go

Thoughts?

答案1

得分: 0

你误解了包和文件。在Go语言中(与Python相反),一个包由一个目录表示,该目录中的文件只是代码而已。所以你应该导入github.com/JohnDoe/temperature/conversion包。

英文:

You're mistaking packages and file. In go (contrary to say… python), a package is represented by a directory, and files in this directory are nothing more than code. So you should import the github.com/JohnDoe/temperature/conversion package.

huangapple
  • 本文由 发表于 2016年4月14日 17:21:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/36618773.html
匿名

发表评论

匿名网友

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

确定