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
相关产品推荐
相关产品推荐

