2014-03-27 20:40
浏览 172


I have an 'example.go' file where I'm trying to import a directory in the same folder.

I have 'example.go' and the 'lucky' dir in the same folder called 'project'.

Here's how I'm trying to import the 'lucky' dir:

import (
    golucky "goLucky"

But when I run example.go, it looks like it is trying to import it from the go source because it throws the error:

    cannot find package "goLucky" in any of:
    /usr/local/go/src/pkg/goLucky (from $GOROOT)
    ($GOPATH not set)

How can I import the local folder in the same dir as the file?

图片转代码服务由CSDN问答提供 功能建议

我有一个“ example.go”文件,试图在同一文件夹中导入目录。< / p>

我在同一个文件夹“ project”中有“ example.go”和“ lucky”目录。

这就是我要尝试的方法 导入'lucky'目录:

“ fmt” 
 golucky“ goLucky” 
“ io / ioutil” 
“ os” 
)\  n   

但是当我运行example.go时,它似乎正试图从go源导入它,因为它会引发错误: \ n

 在以下任何位置都找不到软件包“ goLucky”:
 / usr / local / go / src / pkg / goLucky(来自$ GOROOT)
(未设置$ GOPATH)


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxia2030 2014-03-27 20:47

    You need to set your GOPATH environment variable and locate your lucky dir within that. See

    So for example, if you set GOPATH=~, then put your lucky.go file in ~/src/lucky/lucky.go then you should be able to import "lucky" successfully.

    点赞 评论

相关推荐 更多相似问题