I have a project structure like this…
app/
main.py
app/
__init__.py
boot.py
server.py
controllers/
__init__.py
home.py
The imports are…
# main.py
from app import server
# server.py
from . import boot
# boot.py
from . import controllers
# controllers/__init__.py
from . import home
# controllers/home.py
from .. import boot
Now all the imports are working except the last one. The error thrown is…
ImportError: cannot import name boot
What’s the problem? (I am using Python 3.2)
You are importing
bootwhich is importingcontrollers, which is then asked to importhome, andhomethen tries to importboot, but it wasn’t done importing yet. Don’t do this, you are creating a circular dependency here.Also see Circular import dependency in Python