How to import a module from a parent directory in a Streamlit project?

Hello everyone, I’ve encountered an issue with importing modules while developing a Streamlit app locally. My project structure is as follows:
Project/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ utils/
β”‚ β”‚ └── processing.py
β”‚ β”œβ”€β”€ pages/
β”‚ β”‚ └── page_2.py
└── main.py
In page_2.py, I want to import the processing.py module located in the utils directory, which is a level up. When I try to use the relative import statement
from ..utils import processing as proc,
I encounter the following error:
ImportError: attempted relative import with no known parent package

The Streamlit app is run with the command streamlit run main.py from the src directory. Is there a way to correctly import the module from the parent directory? Or how should I adjust my project structure to avoid this issue?

Thanks for your help!

According to my knowledge all the subpages should in the same stage of main.py directory. Correct if I’m wrong.

IΒ΄m having the same issue. When I run in console everything works but not in streamlit. Did anyone find a way to solve this?

Start from the basic.

1 Like

This is exactly what I was looking for as well. Thank you!