Viktor Danilov Viktor Danilov - 4 months ago 9
Python Question

Cyclic import error

Whatever I try to import from my

pupils
app, I get an import error. For example:

offices/models.py

from pupils.models import Pupils # => ImportError: cannot import name Pupils


I bet the path is right, PyCharm reads it. Everything imports fine from another apps by the way.

Answer

I guess you meet the cyclic imports problem.

An easy way to fix it is import Pupils later:

def where_you_need_pupils():
    from pupils.models import Pupils
    # do something