FileNotFoundError: [Errno 2] No such file or directory: Image

Hi, when I’m deploying my streamlit app, it shows me this error

2021-04-07 00:06:49.788 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/.local/lib/python3.7/site-packages/streamlit/script_runner.py", line 333, in _run_script
    exec(code, module.__dict__)
  File "/app/covidclassificationpython/CovidClassification.py", line 14, in <module>
    image = Image.open('C:/Users/pavit/Desktop/covid4.jpg')
  File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2904, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/pavit/Desktop/covid4.jpg'

However, when I run the webapp in my localhost it shows me the image.

This is the way I’m loading the image. I tried changing the slashes to the backslashes, and I couldn’t run the app.
image = Image.open(‘C:/Users/pavit/Desktop/covid4.jpg’)
st.image(image, caption=‘ML’, use_column_width=True)

Can someone please help me?

Hi,
you can use this path only when you are running your app locally, when you deploy it, the path to your image should be an url, as your deployed app can not access image from your computer.

Ohhh, ok ok. Perfect. Thank you very much for the answer.

Another question hehehe. The file I’m trying to read is host in my computer, so when I try to run the webapp it says that there is an error reading the file. Should I have to save my csv file in my GitHub repository as well? Or how can I do it?

2 Likes