Skip to content

Replacing get_distribution with importlib.metadata #2230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nopria opened this issue Sep 13, 2022 · 1 comment
Closed

Replacing get_distribution with importlib.metadata #2230

nopria opened this issue Sep 13, 2022 · 1 comment

Comments

@nopria
Copy link

nopria commented Sep 13, 2022

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.

@nopria
Copy link
Author

nopria commented Jan 9, 2023

My issue was indirectly solved, I guess, by Dash 2.7.0 with #2291 which made flask-compress optional, and since I don't need it it's ok for me. I haven't tested if enabling flask-compress with Dash 2.7.1 (current version while I write), but I'm closing the issue, feel free to reopen it if you want to investigate further.

@nopria nopria closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant