我有一个这样的应用程序:
api/
|_app/
|_ __init__.py
|_conf/
|_resources/
|_ __init__.py
|_controller.py
|_dao/
|_ __init__.py
|_thing_dao.py
|_etc...
我想在controller.py
内部的thing_dao.py
中使用函数get_thing_by_id
。在PyCharm中,我开始输入get_thing_by_id
,它提示我自动导入函数。问题是它只是from thing_dao import get_thing_by_id
,但当我尝试运行应用程序(Flask)时,我得到ImportError: No module named 'thing_dao'
。最后我要做的是一个相对导入或从模块级别开始from app.dao.thing_dao import get_thing_by_id
。在
我怀疑这个问题与我的项目结构有关,而不是PyCharm bug。有没有办法让我的项目结构更好地提示PyCharm如何做进口?我已经看过了汽车进口和PyCharm的配置选项,它们很薄,所以我怀疑我做错了什么。在
我发现我的目录被标记为“源根目录”。取消标记可以使导入正常工作。在
相关问题 更多 >
编程相关推荐