Skip to content

PyInstaller / Flask-Compress Version Issue #22

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
KyleKing opened this issue Mar 22, 2021 · 4 comments
Closed

PyInstaller / Flask-Compress Version Issue #22

KyleKing opened this issue Mar 22, 2021 · 4 comments

Comments

@KyleKing
Copy link

KyleKing commented Mar 22, 2021

When building an executable with PyInstaller for a Flask app (in particular with Plotly/Dash that requires flask), there would be an error that flask-compress couldn't be found. However, the package was present; the problem was that the pkg_resources.get_distribution function call couldn't recognize the version

Someone posted a fix to monkey patch get_distribution on StackOverflow that is working for us: https://stackoverflow.com/a/64581070/3219667, but I wondered if this is something that could be fixed in flask-compress?

I'll do a little bit more research this week (I think this might be related to setuptools and flask-compress being a single file?), but I figured it was worth a shot to ask if the flask-compress developers had ever run into this issue before.

@alexprengere
Copy link
Collaborator

I have no experience with PyInstaller. Is there something wrong in the packaging of flask-compress that triggers this? I tried this on a fresh virtualenv and got no issue after installing from PyPI:

>>> import pkg_resources
>>> pkg_resources.get_distribution('flask-compress').version
'1.9.0'

@KyleKing
Copy link
Author

Thanks for the quick reply! The error only happens when frozen, so it could be that PyInstaller isn't copying whatever files that pkg_resources is expecting

I'll take a more in-depth look later and create a reproducible example

@KyleKing
Copy link
Author

KyleKing commented Mar 23, 2021

This is a standalone example: KyleKing/Poetry-EdgeCaseTesting and it looks like this is separate of flask-compress. I'm not really familiar with setuptools/packaging, so I started with what could be easy fixes such as adding a static __version__, using PyInstaller hooks, packaging with poetry, and modifying the setuptools file, but I think I'm missing something for how the setuptools distribution works

importlib can't find flask-compress either (when built with PyInstaller)

import importlib.metadata
print(importlib.metadata.version('flask-compress'))

I'll go ahead and close this issue

@KyleKing
Copy link
Author

Figured it out! PyInstaller has a hook for copying metadata that I needed. I'll submit this to the https://github.com/pyinstaller/pyinstaller-hooks-contrib in #102

from PyInstaller.utils.hooks import copy_metadata
datas = (copy_metadata('flask-compress'))

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

2 participants