FileNotFoundError: [Errno 2] No such file or directory: 'FSnm.png'

When deploying my streamlit app, I keep getting this error, and I don’t know how to fix it:

I would like to display an image and this is my code:

from PIL import Image
imagg = Image.open('FSnm.png')
st.image(imagg, width=None)

I tried linking the path to the image, but the same error would occur. I am confused because the image would just show when running the webapp in my localhost.

Please help!!!

Hi @diditaks, welcome to the Streamlit community!

In this case, your code can’t find the image file to open. Have you tried specifying the exact location of the file in your code? The way you have it specified now, you are using a relative reference to your working directory, which might not be where the picture is actually located.

Best,
Randy

Hello @randyzwitch

I have tried specifying the path to the image, e.g

from PIL import Image
imagg = Image.open(’/path/to/image/’)
st.imagg(imagg, width=None)

but the same error would occur

Maybe try to use:

import streamlit as st
import os

def file_selector(folder_path='.'):
    filenames = os.listdir(folder_path)
    selected_filename = st.selectbox('Select a file', filenames)
    return os.path.join(folder_path, selected_filename)

filename = file_selector()
st.write('You selected `%s`' % filename)

Just to figure out what the path is, then delete the snippet.

Okay thank you, let me try that!

1 Like

So I tried this out, but I still seem to be getting the same error.