pylint 显示工作目录中目录的导入错误

pylint shows import-error with directories inside the working directory

安装 Python 的新版本(从 3.8.1 到 3.8.3)并将其与 Visual Studio 代码一起使用后,我遇到了 pylint 之前没有发生的问题升级。

我的工作目录树如下:

bot
 ┣ cogs
 ┃ ┗ cog.py
 ┣ utils
 ┃ ┗ __init__.py
 ┃ ┗ format.py
 ┣ __init__.py
 ┣ core.py
run.py

run.py 是脚本的 "entry point" 初始化所有东西,在里面做 import bot 工作得很好,pylint 没有问题。相对导入对 pylint 没有问题,因为 core.py 使用 from .utils import ....

但是,在 cog.py 中执行 from bot.utils import ... 时,pylint 一直显示 import-error 问题,该问题不应该出现,因为代码运行正常。

我很困惑为什么升级前没有出现这个问题,我做错了什么吗?如果是,我该如何改变这种行为?

原来我不需要更改 VSC 或 pylint 的任何内容,我在 cogs 中添加了一个 __init__.py 文件并且由于某些奇怪的原因它起作用了。