There is only one rule when it comes to importing files in a Python project.
You have to import the package relative to the directory from where the project is run.
For example in the question main.py should have something like this:
from dir.frontend import *
from dir.dir2.backend import *
But then you'll have to have something like main.py under dir/ which imports dir/dir1/main.py and then run python main.py.
So, try to keep the main.py always in the head directory so you don't have to worry about such a situation as above.
ONLY ONE RULE: Everything has to be imported relatively to the directory from where the project is run.