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