Pycharm中 import 引入同级文件失败问题

Pycharm中 import 引入同级文件失败,如下所示:

 “This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.”

在同一个文件夹 (rlso4_afterSample)下的各个 python 文件,在 “generate_item_session.py” 中import  read_from_file 出现了问题,下划红色波浪线。即引用失败。

1、尝试在前面加 “ from . ” ,依然不行:尽管没有提示红色波浪线了,但运行时出错了:

3、尝试使用   from .input 等:

原先:

改后:

 然而,,运行时依然会 报错::

4、最后,尝试把from后面的 . 去掉,并将对应的文件改为类文件。

尽管仍然有红色波浪线,但是运行不出错了,,

原文地址:https://www.cnblogs.com/shenxiaolin/p/8721899.html