I want to know which is the path of my .py

I have a repo created in GitHub already, with some folders, in one of these is my .py, the one is executing by streamlit.

Now, I tried to deploy the app and everything is good till, show up this error.

2023-02-15 12:56:59.338 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/startup-predictions/streamlit/proyecto.py", line 15, in <module>

    with open('model_miguel_recall.pkl', 'rb') as re:

FileNotFoundError: [Errno 2] No such file or directory: 'model_miguel_recall.pkl'

when I tried on my host, it work properly, cause this pkl is in the same path of .py, so the path has been written correctly.

I will appreciate some help.


Please share a link to your public github repo, so that we can have a look at your file structure.

1 Like

Prepend streamlit/ to the paths in 1, 2, 3.

E.g. with open('streamlit/model_miguel_recall.pkl', 'rb') as re:.

Also either comment out this line or upload that image to your repo.

Once you make those changes, your app should successfully load the model:


Thanks a lot, @snehankekre.

It is running great.

Have a good day

Hello there, I am finding the same issue.

I opened in my local host correctly, but when I use my own link from streamlit I have gotten this error:

File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)
File "/app/startup-predictions/streamlit/proyecto.py", line 28, in <module>
    img = Image.open('streamlit/introfoto.jpeg')
File "/home/appuser/venv/lib/python3.10/site-packages/PIL/Image.py", line 3227, in open
    fp = builtins.open(filename, "rb")

But I reorganized the folder, to get not messy. This is my repo:

Thanks a lot

deployment works correctly with this path:

with open('streamlit/model/model_miguel_recall.pkl', 'rb') as re:
    recall_model = pickle.load(re)

but in localhost that path doesn’t work, I don’t understand why?


Because the working directory is different. In the deployment environment the working directory is the root of the repository /app/startup-predictions so the relative path to the pickled model is streamlit/model/model_miguel_recall.pkl.

The working directory is usually where the python interpreter is launched.