简体   繁体   中英

Golang package imports - cannot find package

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM