I am running my multi-page streamlit app locally right now, and I have tried multiple approaches to solving this issue (I see others have the same issue) which is I need to import classes I created into a pages/_1_page.py. So I have tried three approaches:
APPROACH 1:
Use the following folder structure:
|__frontend
|___main.py
|___util_1.py
|___pages
|__page.py
In page.py I want to import MyClass, a class found in util_1.py. I have tried:
from src.frontend.pages.util_1.py import *
APPROACH 2:
I tried changing the file structure so that util_1.py is in a subdirectory underneath pages like this:
|__frontend
|___main.py
|___pages
|__page.py
|__subdirectory
|___util_1.py
Then I had page.py like this:
from src.frontend.pages.subdirectory import util_1
I have also tried (as some have suggested):
from pages.subdirectory import util_1
Neither worked. I don’t want to just put util_1 under the pages folder or else it will automatically show up as a page which I don’t want.
APPROACH 3:
I have tried to solve this programmatically using either:
sys.path.append(str(Path(__file__).resolve().parent.parent))
OR
sys.path.append(os.path.dirname(os.path.abspath(__file__))+"../")
Neither worked.
QUESTION:
There has GOT to be a way to import my own code (not just third party libraries) into a page, no?
I saw on one chat that it could be a requirements.txt issue, but that should only be for third party libraries, correct? Not python modules I create in my own file structure, right?