英文:
could not import ... (no required module provides package ".../utils/...")
问题
好的,以下是翻译的内容:
好的,我现在完全被难住了。我已经查看了这4个类似的问题/答案:
https://stackoverflow.com/questions/70842657/go-no-required-module-provides-package-mux-error
https://stackoverflow.com/questions/65716220/could-not-import-no-required-module-provides-package
https://stackoverflow.com/questions/60680470/could-not-import-local-modules-in-golang
https://stackoverflow.com/questions/58518588/vscode-could-not-import-golang-package
...它们基本上都重复了相同的答案,即运行go mod init <name>和go mod tidy,我已经多次尝试过,但问题仍然存在。
我没有将这个包上传到 GitHub 存储库中,它只是存储在我 Windows 机器的本地位置。我已经运行了以下命令:
go mod init go_backtest
go mod tidy
...但我仍然在各个地方看到这些问题:
有趣的是,在"go_backtest/strategies"这一行下面没有红色下划线:
这是 go.mod 文件的内容:
module go_backtest
go 1.19
我对 golang 还是新手,请多多包涵,但我该如何使其“编译”和运行(并消除那些红色下划线!)
英文:
Ok I'm officially stumped. I've reviewed these 4 similar questions/answers:
https://stackoverflow.com/questions/70842657/go-no-required-module-provides-package-mux-error
https://stackoverflow.com/questions/65716220/could-not-import-no-required-module-provides-package
https://stackoverflow.com/questions/60680470/could-not-import-local-modules-in-golang
https://stackoverflow.com/questions/58518588/vscode-could-not-import-golang-package
...and they all basically repeat the same answer of running go mod init <name> and go mod tidy which I've done numerous times, same issue persists.
I do not have this package uploaded to a github repo, it's just stored locally on my Windows machine. I have run the commands:
go mod init go_backtest
go mod tidy
...and I am still seeing these all over the place:
what's interesting is there is NOT a red underline under the "go_backtest/strategies" line:
This is what the go.mod file looks like:
module go_backtest
go 1.19
I'm still a newbie to golang so be kind, but how can I get this thing to "compile" and run (and make those red underlines go away!)
答案1
得分: 2
utils目录中的文件应该属于同一个包utils。这些文件应该在开头有一行package utils。
而import语句用于导入一个包而不是一个文件。所以将
"go_backtest/utils/dataFuncs"
"go_backtest/utils/ga"
替换为
"go_backtest/utils"
英文:
The files in the utils directory should belong to the same package utils. Those files should have the line package utils at the very beginning.
And the import statement is used to import a package instead of a file. So replace
"go_backtest/utils/dataFuncs"
"go_backtest/utils/ga"
with
"go_backtest/utils"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。




评论