I know there are a lot of readings for this topic available, but I can't figure out how to get it work for my specific case.
I have a project structure like this
root
folder1
__init__.py
file1.py
file2.py
folder2
__init__.py
file3.py
file4.py
folder3
__init__.py
file5.py
In file3.py I have a function getNumbers() which i want to import in file2.py like this:
from folder2.file3 import getNumbers()
The __init__.py files are all empty.
I do get Error if I run file2.py from folder1-directory
No module named 'folder2'
How can i get the import from different subdirectories work?
from folder2.file3 import getNumbers()is invalid syntax: you should usefrom folder2.file3 import getNumbers. By the way, if you run your program from therootfolder then the import infile2.pyworks fine: I know this is not what you asked, but you might want to consider structuring your program that way if you can (it makes your program more modular/better encapsulated).sys.pathhack you use to fix a bad project structure.