0

I am currently running a python code on jupyter notebook. Its a basic dash app tutorial I pulled from the dash documentation. I checked the source code and its up to date (running werkzeug version 2.1.1)

app = Dash(__name__)

df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
    })

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")


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

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

    dcc.Graph(
        id='example-graph',
        figure=fig
        )
    ])


if __name__ == '__main__':
    app.run_server(debug=True)

I get this error when trying to run the above code:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-36-a81edd5f2a5b> in <module>
     25 
     26 if __name__ == '__main__':
---> 27     app.run_server(debug=True)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\dash\dash.py in run_server(self, port, debug, dev_tools_serve_dev_bundles, dev_tools_hot_reload, dev_tools_hot_reload_interval, dev_tools_hot_reload_watch_interval, dev_tools_hot_reload_max_retry, dev_tools_silence_routes_logging, **flask_run_options)
   1283                     )
   1284 
-> 1285                 return dict(
   1286                     user_callback_output=map_grouping(lambda x: no_update, output),
   1287                     interval_disabled=False,

~\AppData\Local\Continuum\anaconda3\lib\site-packages\flask\app.py in run(self, host, port, debug, load_dotenv, **options)
    938         cli.show_server_banner(self.env, self.debug, self.name, False)
    939 
--> 940         from werkzeug.serving import run_simple
    941 
    942         try:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\werkzeug\serving.py in <module>
     26 
     27 from ._internal import _log
---> 28 from ._internal import _wsgi_encoding_dance
     29 from .exceptions import InternalServerError
     30 from .urls import uri_to_iri

ImportError: cannot import name '_wsgi_encoding_dance' from 'werkzeug._internal' (C:\Users\vmehta\AppData\Local\Continuum\anaconda3\lib\site-packages\werkzeug\_internal.py)
vedant mehta
  • 13
  • 1
  • 3
  • Check this thread out, recent WerkZeug update could be the issue, https://stackoverflow.com/questions/71654590/dash-importerror-cannot-import-name-get-current-traceback-from-werkzeug-debu – Daniel Al Mouiee Apr 03 '22 at 10:16
  • @DanielAlMouiee I tried downgrading WerkZeug as per this link but getting the same error. – vedant mehta Apr 03 '22 at 17:18

1 Answers1

1

The error code is saying that it is trying to do relative import and it cannot find the file _wsgi_encoding_dance in the _internal folder within the site-packages/werkzeug package.

Check the package requirements and make sure to install the correct package dependency versions.

anonymous
  • 56
  • 3
  • Thanks for your reply. I checked the `_internal.py` within `werkzeug` package and everything seems to be alright. I could find `_wsgi_encoding_dance` function in there. – vedant mehta Apr 03 '22 at 17:12
  • I would recommend you to post your question as an "Issue" on their GitHub since this question is Library specific and the package dependency issue could vary in each Werkzeug version. https://github.com/pallets/werkzeug/issues Please also provide the version of your Python and the version of your Werkzeug when you create your thread. – anonymous Apr 03 '22 at 19:23