What's best for importing python path for whole project

I have a project with quite a few 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

      

As module1.py

I have done in 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')

      

This way I can import all modules from two folders up. I saw in StackOverflow question that I could create a setup file that would import. Then I still have to do load()

at every entry point. If I put this download function in myproject/load.py

, I still have to add my project to the python path at each entry point.

So my question is, is there a way to use __init__.py

the project folder to automatically import all files if I run any module in any package / subfolder?

PS: Sorry I didn't comment on the other question, but I don't have enough reputation so far.

+3


source to share





All Articles