ModuleNotFoundError for internal imports upon publishing dash app

I am trying to publish a dash app via plotly cloud. The app works without error when run on a local host but when I try to publish the app i get ModuleNotFoundError error regarding internal imports in the run rime on plotly-cloud.

I am using python v.3.13, dash[cloud] v.4.0.0, plotly v.6.5.2, dcc v.2.0.0, dbc v.2.0.4, plotly cloud v.0.1.0, and gunicorn v.24.0.0. I run the code with uv on a mac. The relevant parts of my file structure are as follows:

root_folder/
├── Procfile
├── pyproject.toml
├── requirements.txt
├── src/
│   ├── __init__.py
│   ├── main.py                                    # entry point for code is here
│   ├── app/
│   │   ├── .DS_Store
│   │   ├── __init__.py
│   │   ├── app_factory.py
│   │   ├── components/
│   │   │   ├── __init__.py
│   │   │   ├── page_1.py
│   │   │   ├── page_2.py
│   │   │   └── etc.py
│   │   ├── dashboard_logic.py                 # ModuleNotFoundError is here when calling get_slider_params 
│   │   └── plotly-cloud.toml
└── uv.lock

I use main as the entry point here because I have a separate data loading, processing and validation schema (all not shown here). I assume that the data pipeline in the src folder (and now shown here) play no role in the error. The error arises at the first internal import called in app_factory, which I have called as an absolute import as follows:

from .dashboard_logic import get_slider_params

The dash app is created in main via the following code.

from app.app_factory import create_dash_app

if __name__ == "__main__":
    app = create_dash_app(*args)
    app.run(debug=True, use_reloader=False, port=8051)
    server = app.server

I get this output with the build (all standard imports also seem to load well - not shown here):

Build
Archive:  /tmp/app.zip
  inflating: /home/appuser/app/app_factory.py  
  inflating: /home/appuser/app/.DS_Store  
  inflating: /home/appuser/app/dashboard_logic.py  
  inflating: /home/appuser/app/__init__.py  
  inflating: /home/appuser/app/plotly-cloud.toml  
  inflating: /home/appuser/app/base_graphs.py  
  inflating: /home/appuser/app/components/home.py  
  inflating: /home/appuser/app/components/__init__.py  
  inflating: /home/appuser/app/components/night_vs_day_feeds.py  
  inflating: /home/appuser/app/components/individual_feeds.py 

and these errors in the runtime:

2026-02-10T13:52:49.619Z:   File "/home/appuser/app/app_factory.py", line 12, in <module>
2026-02-10T13:52:49.619Z:     from .dashboard_logic import get_slider_params
2026-02-10T13:52:49.619Z: ImportError: attempted relative import with no known parent

I have separately tried loading the imports in the __init__.py files in the components and app folders, as well as using relative imports. I have tried adding the src folder to the pythonpath. In all attempts mentioned above, the app runs without error on a local host and it is only when i try to publish the app via plotly-cloud that i get the failure message referenced above.

I have seen some questions relating to third-party imports but I have not seen found an similar posts on issues relating to internal imports…Can you help me identify why this is not working and what I can do to resolve this?

When publishing the app via dev tools within plotly cloud, the builder appears to use the __name__ parameter to define the root folder. Therefore, if as in the instance of my code, you do not manually set the __name__ argument when calling Dash() command, then the existing file name is used as the parameter and assumed to be the root of the folder. Therefore then plotly cloud builds the app, any files in parent folders are excluded from the build - causing the import errors.

The issue raised by me above is caused by the instantiation of the dash app within app_factory.py, with the following command:

src/app/app_factory.py

from dash import Dash

# Instantiate app
app = Dash(__name__, additional_args*)

# More code to setup & run app...

I have resolved this issue by instantiating the app (via the code above) in main.py. Alternatively you can set the __name__ parameter to the root folder when instantiating within src/app/app_factory.py, although I am not sure if this approach has any unintended side effects.

For reference, gunicorn is used in plotly cloud to build the application, and setting the root folder in the procfile to the root folder or to src did not resolve the issue (although I am not an expert build commands with gunicorn adjusting the build command may be another route to solving this issue).