There is such a file structure

enter image description here

The test.py file to start at

from .observer import Observer 

When performing issues

  Traceback (most recent call last): File "test.py", line 1, in <module> from .observer import Observer ModuleNotFoundError: No module named '__main__.observer'; '__main__' is not a package 

Help me deal with the import of classes from other files.

  • If you run Observer1/test.py , then you don’t have any Observer1 module and cannot import submodules from it (and the __init__.py file is absolutely useless). Or import the adjacent files as normal modules from observer import Observer , or do not run test.py directly - andreymal 7:33 pm
  • @andreymal, i.e. do i need to render test.py for observer1? Then init .py will be useful and import do from Observer1 import observer? - thecoder
  • As an option. Or (did not remember yesterday), run the file not as a file, but as a submodule python -m Observer1.test - andreymal

0