##### **go env 关键数据是这样的 **
###### **GOPATH="/home/zzy/goProject"**
###### **GOROOT="/usr/local/go"**
###### 项目目录是这样的
```
goProject
├── bin
├── pkg
└── src
└── go_learn
└── day01
├── hello
│ ├── hello
│ └── hello.go
└── str_type
├── str.go
└── world.go
```
##### hello.go我的代码是这样的
```
package main
import (
"fmt"
"go_learn/day01/str_type/world" ## 这句导入包,一直报错
)
func main() {
fmt.Print("hello world")
test()
}
```
##### world.go代码是这样的
```
package main
import "fmt"
func test() {
fmt.Print("啦啦啦啦")
}
```
###### go build 报错是这样的
```
$ go build
hello.go:5:2: cannot find package "go_learn/day01/str_type/world" in any of:
/usr/local/go/src/go_learn/day01/str_type/world (from $GOROOT)
/home/zzy/goProject/src/go_learn/day01/str_type/world (from $GOPATH)
```
##### 我自己查路径,是有world 包的
##### 求 大神解释,感觉是很简单的问题啊,自己太菜了
<a href="/user/rekca" title="@rekca">@rekca</a> 可是我这个不是包,world.go是个文件,所以我要导入到文件写全路径go_learn/day01/str_type/world 吧,运行是可以的
#11
更多评论