I've tried too many solutions that are provided here on SO but wasn't able to make this work.
here is directory structure.
|project
|------->folder1
|-------------->file1.py #file1.py contains class File1
|-------------->file2.py #file2.py contains class File2
|------->folder2
|-------------->another_file1.py #another_file1.py contains class SomeClass1
|-------------->another_file2.py #another_file2.py contains class SomeClass2
|------->Runner
|-------------->logic.py
I need to create instance of all the classes here in logic.py
I created __init__.py
in all folders, and one in the main project.
__init__.py # folder1
from . import file1
from . import file2
__init__.py # folder2
from . import another_file1
from . import another_file2
__init__.py # project
from . import folder1
from . import folder2
I'm unable to import any of stuff inside Runner
.
I get following errors.
No module named file1.
No module named file2.
SystemError: Parent module '' not loaded, cannot perform relative import
However I can make it to work by this tweak.
import sys
sys.path.append('../')
in my files inside Runner
directory. But I don't want to do this in my every file.
P.S. using Python 3.5