Importing objects from app.py into lower directories?

If I have project:

project
    app.py
    dir_A
        pages.py
        config.py
        __init__.py

When I try to import an object, say, variable x, from app.py into pages.py, I have tried:
from .. app import x but it produces an error saying that it is above the parent package

I have also tried placing __init__.py in the project directory, but from what I have read and observed, this doesn’t work since __init__.py cannot be in the package of the module being executed.

Is there a solution to this that would also work well when deploying to Elastic Beanstalk or other services?

thank you

There seem to be a couple of options that you can try here:

I’ve used the sys.path.append before.

1 Like