PyInstaller / Flask-Compress Version Issue
KyleKing opened this issue · comments
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.
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'
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
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
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'))