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

y.s*_*hyk 5 import pycharm

比如说,我的项目结构如下:

project_folder:
  __init__.py
  another_folder:
    __init__.py
    main_file.py
    other_file.py
Run Code Online (Sandbox Code Playgroud)

main_file.py包含下一个代码:

import other_file as whatever
Run Code Online (Sandbox Code Playgroud)

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

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

Car*_*man 8

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