Pycharm导入无法识别同一模块中的其他文件

时间:2016-08-14 12:29:38

标签: import pycharm

说,我的项目结构如下:

project_folder:
  __init__.py
  another_folder:
    __init__.py
    main_file.py
    other_file.py

main_file.py包含下一个代码:

import other_file as whatever

PyCharm(PEP8)将此行突出显示为“no module named other_file”错误,并且在whatever.this_should_be_autoc_suggested等任何调用中都没有自动完成功能。同时翻译工作得非常好。

这种烦人行为的原因是什么?

1 个答案:

答案 0 :(得分:8)

您需要将项目目录标记为“Sources Root”,只需右键单击pycharm中的目录,Mark Directory as,Sources Root。这应该成为你的伎俩。

相关问题