I have a project with quite some packages and modules and many modules have an entry point.
my_project/
package1/
subpackage1/
__init__.py
module1.py
subpackage2/
...
__init__.py
package2/
subpackage3/
...
__init__.py
In in module1.py
I would do at the beginning
path = os.path.abspath(os.path.dirname(__file__)
for i in range(2):
path = os.path.split(path)[0]
sys.path.append(path + '/package1')
sys.path.append(path + '/package2')
Thus I can import all modules from two folder upwards. I saw at https://stackoverflow.com/a/6466248/1449104 that I could create a setup file which does the imports. Then I still have to do load()
at every entry point. If I place this load function in myproject/load.py
I still have to add my project to the python path at every entry point.
So my question is: Is there a way to use the __init__.py
in the project folder to do all the imports automatically if I run any module in any package/subpackage?
PS: Sorry that I did not comment in the other question but I do not have enough reputation till now.