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 ='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.


Hello @randyzwitch

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

from PIL import Image
imagg =’/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.

1 Like

Okay thank you, let me try that!

1 Like

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

When you open a file with the file name , you are telling the open() function that your file is in the current working directory. This is called a relative path. If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. A good start would be validating the input. In other words, you can make sure that the user has indeed typed a correct path for a real existing file, like this:

while not os.path.isfile(fileName):
    fileName = input("No such file! Please enter the name of the file you'd like to use.")

Another way to tell the python file open() function where your file is located is by using an absolute path, e.g.:

f = open("/Users/foo/filename")

I’m having the same issue. Was anyone able to figure out the structure of Streamlit? The file that I need to open is in the same directory as my Streamlit app, but it’s not able to find it with a relative path.

If the image is in /app then the image is in the parent folder of, which is '../FSnm.png'.

Thanks for the reply! I worked around by using the following code:
path = os.path.dirname(__file__)
my_file = path+'/photo.png'

1 Like

Hi @AColocho :grinning_face_with_smiling_eyes:

Was your reply meant for this thread on SpaCy models? OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package - #10 by AColocho

Glad you found a solution! Here’s a related discussion.

Happy Streamlit-ing! :balloon:

It was! I will move it over to the appropriate discussion, and remove this one. Thanks!

Hi, so I had a similar issue. My images are being imported just fine when I’m running the program on my localhost, but as soon as I push it to GitHub, it gives an error that the image couldn’t be found. The File path specified is correct since it’s working on the local host(I’m providing a relative path since the image is located in the same directory).


Me too! I have no clue how to get the file in the correct directory

Hi @chenw-3 :wave:

Your model isn’t loading because the specified filename is incorrect. Line 12 should read

model = pickle.load(open('price_model.pkl', 'rb'))

Note the correct file extension is .pkl, while the one in your app is .pickle.

Here’s your app with the :point_up: changes:

import streamlit as st
import pandas as pd
import pickle
import string
from sklearn.ensemble import RandomForestRegressor

#load model:
model = pickle.load(open('price_model.pkl', 'rb'))

def main():
    # Title
    st.title('Hi there! Welcome to the Jamaican House Price Predictor')

    # header
    st.header('Fill out the following then press submit to get a rough estimate of what your house could be sold for!')

    # no. of beds slider
    beds = st.slider(label='Number of Bedrooms', max_value=10)

    # no. of bathrooms slider
    baths = st.slider(label='Number of Bathrooms', max_value=10)

    #Total sqft slider
    size = st.number_input(label='Total size of the house in Sqft', max_value=10000)

    #region slider
    location = st.slider(label='Kingston', max_value=20)


    inputs = [[beds, baths, size, location]]

    if st.button(label='Submit'): #button
        result = model.predict(inputs)
        updated_results = result.flatten().astype(int)
        st.success('Your house could be listed at JMD{} million'.format(updated_results))

if __name__ =='__main__':

Happy Streamlit’ing! :balloon:

1 Like

Hi @Aditya_Nayak, welcome to the Streamlit community!! :wave: :partying_face:

Would you mind dropping a link to your GitHub repo? It would help us with debugging your issue.

Best, :balloon:

Thanks for catching that! I also moed the file out of my notebooks folder and that helped as well. Thanks for helping!!

1 Like

I am trying to deploy my streamlit app and it says file error not found for my pickle location. Please help me. This is the GitHub link.


Hello, I have the same problem. Is it possible to help me ?