Error while trying to upload image from my repo while deploying : No such file or directory

Hi,

I’m trying deploying my first streamlit app.

I want to put a sample of images. But when I run my app, I have this error message :

Whereas when I looked in my github, the image is here (link to the directory of image) :

It seems the problem is in the function below.
But I’ve tried several solutions to fix that and search in previous posts about this subject :
put

None of these solutions work.

It works when I run in the local way.

my github repo is here : git

Have you tried without the first slash?

filename = f"image_train/image_{row.imageid}_product_{row.productid}.jpg"

Generally i would not treat file paths as strings, it can cause all sorts of issues, especially when running cross-platform. I would use the builtin pathlib standard library.

Yes I’ve tried it also and it doesn’t work.

I don’t know path library (i’m new in using python and streamlit).
I’m going to try and let you know if it works.

Thank you

I tried with Pathlib but I have the same message.

I’ve noticed one difference : In the message error, when I use pathlib, it didn’t detect the specific image to select.
Cf in the message error, it doesn’t traduct “{row.image_id}” and “{row.product_id}” while with filename it was working.

Here the code I’ve tried with pathlib :

I’m lost because I really don’t understand what’s wrong

You still have to use the f-string:

path_image=pathlib.Path(f'image_train/path_image/image_{row.imageid}_product_{row.productid}.jpg')

However this path is wrong anyway and does not exist:

/image_train/path_image/

Ok.
I put the correction :

             path_image=pathlib.Path(f'/image_train/image_{row.imageid}_product_{row.productid}.jpg')
             image = Image.open(path_image)
             cols[index].image(image, use_column_width=True)
             index += 1

I have the exact error message than with the filename solution.

The code give the right name of the image, but even if the path it right, it doesn’t work.

Take a look at all the images in the img_train and img_test subfolders, they all seems to be no valid jpg images.

1 Like

Wouaw, I didn’t see this. Th eupload was fine.
I’ve corrected this also. But I really think there is something missing or something I should know about upload images for Streamlit App.

I have the same message error.

I even tried to use “webp” format and it doesn’t change anything.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.