Pylint 对工作相关导入发出错误警告

发布于 2025-01-19 03:15:11 字数 730 浏览 3 评论 0原文

我有以下文件结构:

├── README.md
├── apps
│   ├── fire_analysis.py
│   └── rois.py
└── streamlit_app.py

文件目录

  • slectlit_app.py
from apps import fire_analysis

  • apps/fire_analysis.py
from .apps import rois
print(rois.the_object)

  • apps/rois.py
the_object = 42 # the object that I want

代码工作正常。但是我得到了e0402:超出顶级软件包(相对范围级别)的尝试相对导入的来自Pylint的错误警告。

如何解决此警告? 我是在fire_analysis.py中以错误的方式导入的方式?

I have the following file structure:

├── README.md
├── apps
│   ├── fire_analysis.py
│   └── rois.py
└── streamlit_app.py

File contents

  • streamlit_app.py
from apps import fire_analysis

  • apps/fire_analysis.py
from .apps import rois
print(rois.the_object)

  • apps/rois.py
the_object = 42 # the object that I want

The code works just fine. But I am getting the E0402: Attempted relative import beyond top-level package (relative-beyond-top-level) error warning from pylint.

How to resolve this warning?
Am I doing the importing the wrong way in the fire_analysis.py?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹂绝世的画 2025-01-26 03:15:11

它可以更改apps/fire_analysis.py的导入到

from . import rois

告诉Python进行本地搜索。

It works for me to change the import of apps/fire_analysis.py to

from . import rois

telling python to search locally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文