My project contains only four modules in single directory. Everything worked fine before I tried to add additional setup menu. Now I get ImportError
when class exists in this module:
python3 -m project
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/project/__main__.py", line 1, in <module>
from project.gui import Window
File "/home/project/gui.py", line 4, in <module>
from project.document import Document
File "/home/project/document.py", line 3, in <module>
from project.salary import Salary
File "/home/project/salary.py", line 3, in <module>
from project.gui import Setup
ImportError: cannot import name 'Setup' from 'project.gui' (/project/gui.py)
Here is structure (modules, imports, classes, data) of my project:
* document.py
from project.salary import Salary
class Record
class Document
* gui.py
from project.document import Document
from project.predefined import VALUES
class Gui(tk.Tk)
class Window(Gui)
class Setup(Gui)
* __main__.py
from project.gui import Window
* salary.py
from project.gui import Setup
dataclass Record
VALUES = (Records, )
class Loader
class Salary
* predefined.py
dataclass Record
VALUES = (Records, )
I don't understand why it is happening, everything seems to be allright for me. Could you explain me please this behaviour and how can I fix it?
Edit: I have changed structure of project to avoid circular import dependency as suggested in comments. Updated structure is up (dataclass Record
and VALUES
are temporary duplicated in salary.py
and predefined.py
). I still get the same error.