You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pylint报相对导入相关的E0611错误但代码实际可运行的问题求助

Pylint报相对导入相关的E0611错误但代码实际可运行的问题求助

我遇到个头疼的问题——Pylint一直在抱怨相对导入的问题,但我的代码明明能正常运行。我知道可以直接忽略这个警告,但我不想这么做,想彻底解决它。

我的项目结构是这样的:

project_root/
├── main.py
├── instruments/
│   ├── __init__.py
│   ├── my_instrument/
│   │   ├── __init__.py
│   │   └── my_instrument.py

其中instruments/__init__.py是空的,而instruments/my_instrument/__init__.py里写了这行代码:

from .my_instrument.py import my_function

在main.py里,我是这么导入my_function的:

from instruments.my_instrument import my_function

这段代码运行完全没问题,但Pylint却抛出了错误:

No name "my_function" in module "instruments.my_instrument"
Pylint(E0611:no-name-in-module)

真心希望有人能帮我解决这个问题,谢谢啦!

备注:内容来源于stack exchange,提问作者Geo48

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:47:57