ImportError: cannot resolve import name

Copy

http://d.hatena.ne.jp/machua/20101026/1288099599

Event

Occurs when calling modules to each other with the following module structure.

file organization


view\
    __init__.py
    form1.py
    form2.py

form1.py


from veiw.fom2 import frm2
class frm1 ():
    ....

form2.py


from veiw.fom1 import frm1
class frm2 ():
    ....

Cause

At the time of import, I am getting an error because I am importing myself (I think) By the way, it also occurs when you create a module with the same name as the built-in module.

solution

Instead of importing globally, import within the class. For example, in the constructor or in the function just before calling the screen.

form1.py


class frm1 ():
    def __init__(self):
        from veiw.fom2 import frm2
        self.fm = frm2()

Recommended Posts

ImportError: cannot resolve import name
ImportError: cannot resolve import name
ImportError: cannot import name'factorial' ~ ~ ~
ImportError: cannot import name'_check_sample_weight'
from scipy.misc If "ImportError: cannot import name imread" occurs in import imread, imresize
Cannot import name'NUMPY_MKL'Solution.
When it becomes Cannot import name "Feature" from "setuptools".
What to do when "cannot import name xxx" [Python]
Resolve VS Code unresolved import error
If you are told cannot by Python import, review the file name