Skip to content

The 'flask-compress' distribution was not found and is required by the application #1606

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
europa502 opened this issue Apr 27, 2021 · 10 comments

Comments

@europa502
Copy link

When using cx_freeze to build a dash app I get the following error-

Traceback (most recent call last):
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 81, in run
    module.run()
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\cx_Freeze\initscripts\Console.py", line 36, in run
    exec(code, m.__dict__)
  File "strata.py", line 1, in <module>
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\dash_core_components\__init__.py", line 6, in <module>
    import dash as _dash
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\dash\__init__.py", line 5, in <module>
    from .dash import Dash, no_update  # noqa: F401,E402
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\dash\dash.py", line 53, in <module>
    _flask_compress_version = parse_version(get_distribution("flask-compress").version)
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 480, in get_distribution
    dist = get_provider(dist)
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 356, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 899, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Users\menonAbhijit\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 785, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'flask-compress' distribution was not found and is required by the application


Here are the versions of dash and flask modules I'm using-

dash==1.19.0
dash-bootstrap-components==0.12.0
dash-core-components==1.15.0
dash-html-components==1.1.2
dash-renderer==1.9.0
dash-table==4.11.2
Flask==1.1.2
Flask-Compress==1.9.0

The issue is in this line -

_flask_compress_version = parse_version(get_distribution("flask-compress").version)

I do understand why this could be a problem. When building cx_freeze imports the required packages. Hence, Flask-Compress is imported as flask_compress. While all the imports work well within the built app, when a package is verified with its name.

I dug a little deeper to see if there was any attribute being set in the package that'd help us get the version info simply by importing it into dash.py, but I couldn't find any. I have opened an issue here as well -colour-science/flask-compress#23 (comment)

Please let me know if there is any fix for the cx_freeze issue.

@alexcjohnson
Copy link
Collaborator

Thanks @europa502! We're going to need the pkg_resoureces solution regardless, since the version distinction we care about (>=1.6.0) doesn't have a __version__ attribute, but I do appreciate you pushing for an upstream fix!

On my system get_distribution works equally well whether I capitalize the package or not:

>>> from pkg_resources import get_distribution, parse_version
>>> get_distribution('flask-compress')
Flask-Compress 1.5.0 (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages)
>>> get_distribution('Flask-Compress')
Flask-Compress 1.5.0 (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages)

But it appears the canonical name is capitalized, and the implication is that on your system only the capitalized version succeeds, in which case the solution is simply to use the capitalized name? Though, if that were the problem you wouldn't be able to run Dash at all on your system, so it sounds rather as though there's something funny about calling get_distribution within cx_freeze. Then we could just wrap that call in a try/except, yielding a dummy (low?) version number if it fails.

@anders-kiaer
Copy link
Contributor

Only slightly related to the initial issue description, but I can recommend importlib.metadata. I find it more robust + efficient + cleaner API compared to setuptools' pkg_resources. AND it is part of the Python std.lib on 3.8+, and have a backport for Python 3.6+. I.e. not relevant for Dash today, but might be relevant when Python 2.7 support is dropped (unless solved upstream before that).

from importlib.metadata import version

version("flask-compress")  # == '1.9.0' on my computer

@europa502
Copy link
Author

I built the app again on python 3.6, and it worked like a charm. I face this issue when I try to build it on python 3.9.

A similar issue was raised here, but the merged fix didn't work for me. Eventually I had to use the workaround to make it work with python 3.9.

I'll try to figure out the root cause this weekend.

@europa502
Copy link
Author

This issue is fixed with the release of cx_Freeze 6.7. Thanks!

@giadasp
Copy link

giadasp commented Aug 27, 2021

Hey guys, I'm trying to distribute a simple dash app with cx_freeze (updated to 6.7) but still I have this problem or flask-compress not found.
These are the steps I followed:

  • create a venv
  • activate the venv
  • install packages from requirements. txt:
    dash==1.19.0 dash-bootstrap-components==0.12.0 dash-core-components==1.15.0 dash-html-components==1.1.2 dash-renderer==1.9.0 dash-table==4.11.2 Flask==1.1.2 Flask-Compress==1.9.0
  • create the files app.py, server.py e setup.py as follows:
    app.py:
import dash
import dash_html_components as html
import dash_core_components as dcc

app = dash.Dash(__name__)

server = app.server

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=8049)

server.py:

from waitress import serve

from app1 import app

server = app.server

serve(server, port=8049)

setup.py:

from setuptools import find_packages
from cx_Freeze import setup, Executable


options = {
    'build_exe': {
        'includes': [
            'cx_Logging', 'idna',
        ],
        'packages': [
            'asyncio', 'flask', 'jinja2', 'dash', 'plotly', 'waitress', 'pkg_resources'
        ],
        'excludes': ['tkinter']
    }
}

executables = [
    Executable('server.py',
               base='Win32GUI',    #'console',
               targetName='app1.exe')
]

setup(
    name='app1',
    packages=find_packages(),
    version='0.0.1',
    description='ms',
    executables=executables,
    options=options
)
  • run

python setup.py bdist_msi

  • install the app
  • run the app and I have the error message.

What's wrong with my approach?
Please help me!

@MrJeric0
Copy link

MrJeric0 commented Oct 7, 2021

Hey guys, I'm trying to distribute a simple dash app with cx_freeze (updated to 6.7) but still I have this problem or flask-compress not found. These are the steps I followed:

  • create a venv
  • activate the venv
  • install packages from requirements. txt:
    dash==1.19.0 dash-bootstrap-components==0.12.0 dash-core-components==1.15.0 dash-html-components==1.1.2 dash-renderer==1.9.0 dash-table==4.11.2 Flask==1.1.2 Flask-Compress==1.9.0
  • create the files app.py, server.py e setup.py as follows:
    app.py:
import dash
import dash_html_components as html
import dash_core_components as dcc

app = dash.Dash(__name__)

server = app.server

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=8049)

server.py:

from waitress import serve

from app1 import app

server = app.server

serve(server, port=8049)

setup.py:

from setuptools import find_packages
from cx_Freeze import setup, Executable


options = {
    'build_exe': {
        'includes': [
            'cx_Logging', 'idna',
        ],
        'packages': [
            'asyncio', 'flask', 'jinja2', 'dash', 'plotly', 'waitress', 'pkg_resources'
        ],
        'excludes': ['tkinter']
    }
}

executables = [
    Executable('server.py',
               base='Win32GUI',    #'console',
               targetName='app1.exe')
]

setup(
    name='app1',
    packages=find_packages(),
    version='0.0.1',
    description='ms',
    executables=executables,
    options=options
)
  • run

python setup.py bdist_msi

  • install the app
  • run the app and I have the error message.

What's wrong with my approach? Please help me!

hey did you find a solution to this, im running into it as well. Cheers

@giadasp
Copy link

giadasp commented Oct 7, 2021

Nope :(

@europa502
Copy link
Author

Hey guys, I'm trying to distribute a simple dash app with cx_freeze (updated to 6.7) but still I have this problem or flask-compress not found. These are the steps I followed:

* create a venv

* activate the venv

* install packages from requirements. txt:
  `dash==1.19.0 dash-bootstrap-components==0.12.0 dash-core-components==1.15.0 dash-html-components==1.1.2 dash-renderer==1.9.0 dash-table==4.11.2 Flask==1.1.2 Flask-Compress==1.9.0`

* create the files app.py, server.py e setup.py as follows:
  app.py:
import dash
import dash_html_components as html
import dash_core_components as dcc

app = dash.Dash(__name__)

server = app.server

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=8049)

server.py:

from waitress import serve

from app1 import app

server = app.server

serve(server, port=8049)

setup.py:

from setuptools import find_packages
from cx_Freeze import setup, Executable


options = {
    'build_exe': {
        'includes': [
            'cx_Logging', 'idna',
        ],
        'packages': [
            'asyncio', 'flask', 'jinja2', 'dash', 'plotly', 'waitress', 'pkg_resources'
        ],
        'excludes': ['tkinter']
    }
}

executables = [
    Executable('server.py',
               base='Win32GUI',    #'console',
               targetName='app1.exe')
]

setup(
    name='app1',
    packages=find_packages(),
    version='0.0.1',
    description='ms',
    executables=executables,
    options=options
)
* run

python setup.py bdist_msi

* install the app

* run the app and I have the error message.

What's wrong with my approach? Please help me!

What version of python are you using?

@matthew-leon-quandl
Copy link

still having this issue:(

@YuanJ-i
Copy link

YuanJ-i commented Sep 6, 2022

It originates from pkg_resources.get_distribution, should be updated.
change this line
_flask_compress_version = parse_version(get_distribution("flask-compress").version)
to
_flask_compress_version = parse_version(importlib.metadata.version("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

7 participants