ImportError: no module named foo; AttributeError: 'module' object has no attribute 'bar'

This is likely to be a circular import

You are possibly doing something like:

Form A:

from ..FormB import foo

Form B:

from ..FormA import bar

or likewise

Form A:

from .. import FormB

Form B:

from .. import FormA

One option

you can move import statements into methods or classes to prevent them being circular

Form A:

from ..FormB import foo

Form B:

def some_method():
  from ..FormA import bar

# no longer a circular import :-)

or likewise

Form A:

from .. import FormB

Form B:

def some_method():
  from .. import FormA

# no longer a circular import :-)

Another option

(depending on the attribute you are importing - courtesy of @stefano.menci suggestion below)
You could abstract certain attributes into their own module

Globals (module)

foo = # some python object
bar = # some other python object

Form A:

from Globals import foo

Form B:

from Globals import bar
4 Likes