Reputation: 1768
I have an app structured like so:
api/
|_app/
|_ __init__.py
|_conf/
|_resources/
|_ __init__.py
|_controller.py
|_dao/
|_ __init__.py
|_thing_dao.py
|_etc...
I want to use the function get_thing_by_id
in thing_dao.py
inside of controller.py
. In PyCharm I start to type get_thing_by_id
and it prompts me to auto-import the function. The problem is it simply does from thing_dao import get_thing_by_id
but when I attempt to run the app (Flask) I get ImportError: No module named 'thing_dao'
. What I end up having to do is a relative import or start at the module level from app.dao.thing_dao import get_thing_by_id
.
I suspect this issue is related to my project structure and less of a PyCharm bug. Is there a way I could structure my project to better hint to PyCharm how to do imports? I've looked through the configuration option for auto-imports and PyCharm and they're quite slim so I suspect that I'm doing something wrong.
Upvotes: 2
Views: 622
Reputation: 1768
I discovered I had my directories marked as a "Source Root". Unmarking them made the imports work properly.
Upvotes: 5