dash
dash copied to clipboard
Replacing `get_distribution` with `importlib.metadata`
I have a web app using
dash
dash-bootstrap-components
gunicorn
Pillow
sympy
whitenoise
where in particular
dash==2.6.1
Flask==2.2.2
Flask-Compress==1.12
gunicorn==20.1.0
The Docker image of the app is working fine, but when I tried to reduce its size with docker-slim I got the error
pkg_resources.DistributionNotFound: The 'flask-compress' distribution was not found and is required by the application
Looking for that error I found a comment (about another problem giving the same error) suggesting to replace the line originating the error
_flask_compress_version = parse_version(get_distribution("flask-compress").version)
with
_flask_compress_version = parse_version(importlib.metadata.version("flask-compress"))
As such line happens to be 74th of dash.py, I replaced it on the fly (adding import importlib.metadata before it) and that solved the issue, my slimmed Docker image was working.
Surely mine is a weird issue, but if a solution to another problem was able to solve my issue too, maybe it is worth reporting it, so that some expert can evaluate if the above replacement should be adopted permanently.