I know this question has been asked before but none of the solutions worked for me. So let's say I have a directory structured as follow :
folder1:
-- file1.py
folder2:
-- class2.py
I want to call the class from class2.py in my file1.py so what I did at the start of the file1.py is
from folder2.class2 import Class2
But the following issue arises:
ModuleNotFoundError: No module named 'folder2'
so I tried something else:
from .folder2.class2 import Class2
the following issue arises:
ImportError: attempted relative import with no known parent package
I read a solution on the site where you add __init.py__ in the folder2
but it didn't help.
Any suggestions please? Thank you.
folder1andfolder2) is on yourPYTHONPATH. 2. Make surefolder1andfolder2each contain an__init__.py.