Greetings again.
The application relies on a resource file that’s included in the package. When trying to access it from the app hosted by Streamlit here we get this error:
FileNotFoundError: [Errno 2] No such file or directory: '/home/adminuser/venv/lib/python3.12/site-packages/ssscoring/resources/drop-zones-loc-elev.csv'
The requirements.txt
file uses the publicly available package ssscoring==2.0.0
from PyPI. When downloading the wheel and unzipping the resource is present:
Archive: ssscoring-2.0.0-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
888 01-22-2025 22:27 ssscoring/__init__.py
6909 01-22-2025 22:29 ssscoring/app.py
25775 01-22-2025 22:07 ssscoring/calc.py
4441 12-30-2024 11:37 ssscoring/cli.py
2859 01-22-2025 22:07 ssscoring/constants.py
2070 01-19-2025 01:38 ssscoring/datatypes.py
707 08-28-2023 04:10 ssscoring/errors.py
8506 01-22-2025 22:07 ssscoring/flysight.py
8826 01-22-2025 22:07 ssscoring/notebook.py
15193 01-22-2025 22:07 ssscoring/resources/drop-zones-loc-elev.csv
1529 01-22-2025 22:30 ssscoring-2.0.0.dist-info/LICENSE.txt
8564 01-22-2025 22:30 ssscoring-2.0.0.dist-info/METADATA
91 01-22-2025 22:30 ssscoring-2.0.0.dist-info/WHEEL
58 01-22-2025 22:30 ssscoring-2.0.0.dist-info/entry_points.txt
10 01-22-2025 22:30 ssscoring-2.0.0.dist-info/top_level.txt
1285 01-22-2025 22:30 ssscoring-2.0.0.dist-info/RECORD
--------- -------
87711 16 files
The code that processes the resource works when running Streamlit in the local workstation (macOS, Linux), in a virtual environment. It also works fine when Dockerized using the latest Python Docker image. The FileNotFoundError
only happens in the Streamlit deployment.
The code that uses the resource:
from importlib.resources import files # code is correct, this snippet missed the 's' earlier
from io import StringIO
RESOURCES = 'ssscoring.resources'
RESOURCE_NAME='drop-zones-loc-elev.csv'
.
.
@st.cache_data
def _initDropZonesFromResource(resourceName: str) -> pd.DataFrame:
buffer = StringIO(files(RESOURCES).joinpath(resourceName).read_bytes().decode(FLYSIGHT_FILE_ENCODING))
dropZones = pd.read_csv(buffer, sep=',')
return dropZones
.
.
dropZones = _initDropZonesFromResource(RESOURCE_NAME)
requirements.txt
:
bokeh==2.4.3
click
haversine
importlib-resources
jupyter_bokeh==3.0.4
numpy<1.26.4
psutil
ssscoring==2.0.0
streamlit
ssscoring==2.0.0
is fetched from PyPI. The app reported the same error when the package was pulled from the GitHub repository/branch.
Please advise on how to handle app resources in the Streamlit environment since Python best practice method results in that FileNotFound
error.
Thanks in advance and a have a wonderful evening,
pr3d