PyCharm 中如果自定义的模块引入可用但显示红线,可用如下方法解决
file->settings->project->project structure->点击项目路径->点击Sources (或Excluded)
在package中__init__.py中加入__all__ 的列中,代表列表中的方法是对外开放的,类似带有@export 装饰器的形式。
__all__ = ["ParserInterface", "LogInterface"] from business.parser_interface import ParserInterface from business.log_interface import LogInterface
PyCharm是在root路径和相对路径中查找需要引入的包,如果自定义的方法无法引入,可将其加入root中以使用。
博客介绍了在PyCharm中解决自定义模块引入显示红线问题的方法。可通过file->settings->project->project structure设置项目路径为Sources或Excluded;在package的__init__.py中加入__all__列表;若自定义方法无法引入,可将其加入root路径。

6178

被折叠的 条评论
为什么被折叠?



