Running streamlit from inside a folder causes trouble with environment variables

My project directory ran fine like this:

pages/
  -p1.py
  -p2.py
app.py
utils.py # secret accessed here using os.getenv

And had trouble after changing to:

devapp/
  pages/
    -p1.py
    -p2.py
  app.py
tools/
-utils.py # secret accessed here using os.getenv

I tried storing secrets in heroku and .streamlit/secrets.toml.

Note: to get relative imports to work i.e. from tools.utils import func I had to run it using python -m streamlit run devapp/app.py

Update: adding .streamlit/secrets.toml inside devapp/ doesn’t work either

I was a fool. I missed changing the path of something inside the .py file that I moved into tools/

1 Like