Home > Blockchain >  How to fix an error with images when deploying my streamlit webapp?
How to fix an error with images when deploying my streamlit webapp?

Time:02-11

I started by making a text file (requirements.txt) with all the versions of the libraries used in the code. So I opened a folder on GitHub and added all the necessary files.

I used Streamlit Sharing to deploy and it returned the following error:

File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 379, in _run_script
    exec(code, module.__dict__)
File "/app/orbitas-relativistics/webapp.py", line 15, in <module>
    image1 = Image.open(r'C:/Users/isabe/.streamlit/titulo11.png')
File "/home/appuser/venv/lib/python3.7/site-packages/PIL/Image.py", line 2953, in open
    fp = builtins.open(filename, "rb")

My code doesn't have the command fp = builtins.open(filename, "rb") and it doesn't even have 2953 lines. It only has 395.

About the images, I uploaded them inside the .streamlit folder of my Visual Studio Code (where the code is hosted). And it gives the error

FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/isabe/.streamlit/titulo11.png'

Does anyone know what I should do to fix this error and proceed with the deployment of my site?

Thanks for any help.

CodePudding user response:

In general, referring to exact filenames isn't a good idea when deploying, as it's almost certain that the machine you deploy on will have different drive mappings than your development machine.

In this case, you are using a Windows filepath and Streamlit Cloud is a Debian image. Based on your Git link, your file is located in the root directory, so you can specify image1 = Image.open('titulo11.png') and it will work on Streamlit Cloud (though it may not work on your development machine).

To make your code work on both machines, I suggest using something like pathlib to programmatically determine where a file is located, instead of having to inspect what level of file directory it might be in.

  • Related