goland有独立的env配置,你设置goland的配置才行,goland的gopath应该是空。
我build一个不存在的包xxx,先在goroot然后在多个gopath查找的包,所以仅提示goroot没有就是没有gopath。
[root@localhost _example]# go build xxxx
can't load package: package xxxx: cannot find package "xxxx" in any of:
/usr/local/go1.10/src/xxxx (from $GOROOT)
/root/go/src/xxxx (from $GOPATH)
/mnt/hgfs/gopath/src/xxxx
/data/web/golang/src/xxxx
goland设置打开“File->settings”,弹出如下配置界面:
还有一个需要注意的地方,环境变量GO111MODULE是gomod的开关,on启用,off关闭,auto在gopath内就是启用之外是关闭,设置on值可能有问题,我自己并不使用gomod。
goland有独立的env配置,你设置goland的配置才行,goland的gopath应该是空。
我build一个不存在的包xxx,先在goroot然后在多个gopath查找的包,所以仅提示goroot没有就是没有gopath。
[root@localhost _example]# go build xxxx
can't load package: package xxxx: cannot find package "xxxx" in any of:
/usr/local/go1.10/src/xxxx (from $GOROOT)
/root/go/src/xxxx (from $GOPATH)
/mnt/hgfs/gopath/src/xxxx
/data/web/golang/src/xxxx
goland设置打开“File->settings”,弹出如下配置界面:
还有一个需要注意的地方,环境变量GO111MODULE是gomod的开关,on启用,off关闭,auto在gopath内就是启用之外是关闭,设置on值可能有问题,我自己并不使用gomod。
goland有独立的env配置,你设置goland的配置才行,goland的gopath应该是空。
我build一个不存在的包xxx,先在goroot然后在多个gopath查找的包,所以仅提示goroot没有就是没有gopath。
[root@localhost _example]# go build xxxx
can't load package: package xxxx: cannot find package "xxxx" in any of:
/usr/local/go1.10/src/xxxx (from $GOROOT)
/root/go/src/xxxx (from $GOPATH)
/mnt/hgfs/gopath/src/xxxx
/data/web/golang/src/xxxx
goland设置打开“File->settings”,弹出如下配置界面:
还有一个需要注意的地方,环境变量GO111MODULE是gomod的开关,on启用,off关闭,auto在gopath内就是启用之外是关闭,设置on值可能有问题,我自己并不使用gomod。
因为gomod和gopath两个包管理方案,并且相互不兼容有他没我那样。
在gopath查找包,按照goroot和多gopath目录下src/xxx依次查找。
在gomod下查找包,解析go.mod文件查找包,mod包名就是包的前缀,里面的目录就后续路径了。
在gomod模式下,查找包就不会去gopath查找,只是gomod包缓存在gopath/pkg/mod里面。
还有一种可能,看看是不是goland 的版本太老了。我的是2018.1的,这个时候ide对go module 支持不是很好,采用go mod引本地包的话,ide的build 没法用,换成2020.1版就可以了。(前提条件是你在命令行里面能跑,排除其他的问题)。
推荐文章: