英文:
i am getting error while trying to import go package. who could be appropriate solution for this problem?
问题
无法导入myproject/game/helper2(在任何位置都找不到包“myproject/game/helper2”)
/usr/local/go/src/myproject/game/helper2(来自$GOROOT)
/home/prasnjit/dev/go/src/myproject/game/helper2(来自$GOPATH)编译器
以下是代码的屏幕截图
屏幕截图如下所示。给我一些有用的解决方案?点击此处查看图片描述
我正在尝试在main.go中导入一个包,但在导入时出现错误。我无法确定问题可能是什么。
英文:
could not import myproject/game/helper2 (cannot find package “myproject/game/helper2” in any of
/usr/local/go/src/myproject/game/helper2 (from $GOROOT)
/home/prasnjit/dev/go/src/myproject/game/helper2 (from $GOPATH))compiler
the screen shot of code is attached below
screenshort is given below. Give me some useful solution of it? enter image description here
i am trying to import one package in main.go and getting error while importing. i am not able to configure what could be the problem.
答案1
得分: 1
我会假设你的模块名为"myproject"(在go.mod
中声明)。看起来你想要导入"game"包。
package main
import (
"fmt"
"myproject/game"
)
func main() {
fmt.Println(game.Get())
}
在Go语言中,你导入的是_包_,而不是文件。包通常组织在目录中。Go源文件在顶部声明它们所属的包。在这里了解更多关于Go模块的信息:链接。
英文:
I'll assume your module is called "myproject" (this is declared in go.mod
). It looks like you want to import the "game" package instead.
package main
import (
"fmt"
"myproject/game"
)
func main() {
fmt.Println(game.Get())
}
In Go, you import packages, not files. Packages are typically organized in directories. Go source files declare the package that they belong to on top. Learn more about Go modules here.
答案2
得分: 0
看起来你导入代码的方式不正确。
尝试像这样导入:
import "myproject/game"
如果你正在导入一个包,不需要提及文件名。
查看这个链接
英文:
It seems like you are doing the import wrong.
try like this
import "myproject/game"
If you are importing a package,no need to mention the filename.
Checkout this
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论