Cannot import local files into streamlit app

I am trying to run a streamlit app using local helper functions. My import statements look like this
from src.helper1 import helperfunc
from src.helper2 import helperfunc2
image

I am however being given a module not found error. Importing src from any other file works fine. Just not the web app.

Any help is appreciated! Thanks!

Hey Josh,

Welcome to the Streamlit community! If you could provide the traceback calls that would help us know what this error might be stemming from, also your directory structure may help here as well.

In the mean time, to me, this looks like python can’t find your src file that holds your helper functions in them. Where is this file?

The other files that import properly, where are they in relation to your web app?

Cheers!
Marisa

Hi,

I am also experiencing the same issues. I’m trying to import a secrets file into my streamlit app but cannot import it. My streamlit file and my secrets file are in the same level of the directory. I use from secrets import xxx, xxx, xxx. However when I try to run streamlit it shows the following error:

Thanks!

Hi @nshyam97,

Welcome to the Streamlit Community! There might be a couple of things happening here:

1st is the name of your file: Python 3.8 seems to have its own secrets.py file in “/usr/local/Cellar/etc…”, which is not the directory you are running your files from as that starts with “/Users/etc…”. If you rename your secrets.py file in your CWD to something like my_secrets_file.py that will likely solve the problem if your working locally.

2nd is your directory structure (if your deploying):
if your directory is set up:
“local/directory/structure/my_app/” and in my_app directory is your streamlit_app and your secrets:
“local/directory/structure/my_app/streamlit_app.py”
“local/directory/structure/my_app/secrets.py” (again change this name)
Then it should load, but if it is anything other than this file structure (@joshzwiebel this may help with your issue) then you will need to add this file to the requirements.txt file you need when deploying an app on streamlit share:
“github/repo/your_app/requirements.txt”:
[-e] <github/repo/another_app/my_module.py>

This should work!
Happy Streamlit-ing!
Marisa

2 Likes

Hi @Marisa_Smith

Your 1st suggestion worked perfectly! Thank you. I’ve not had this problem when working outside of streamlit so that was probably why I was a bit stumped.

Thank you!

1 Like

I have a similar problem. But the solution didn’t help. Any thoughts please?

1 Like