5

I'm just trying to get the Dash tutorial up and running but every time I try to run it, copy and pasted from the documentation into my asdf.py I get the error "ImportError: cannot import name 'dcc' from 'dash'". I've tried uninstalling and reinstalling dash, along with renaming the file and got nowhere. Any help is appreciated, thanks!

from dash import Dash, dcc, html, Input, Output

app = Dash(__name__)

app.layout = html.Div([
    html.H6("Change the value in the text box to see callbacks in action!"),
    html.Div([
        "Input: ",
        dcc.Input(id='my-input', value='initial value', type='text')
    ]),
    html.Br(),
    html.Div(id='my-output'),

])
Sameer
  • 59
  • 1
  • 1
  • 5
  • 1
    Sounds like a version issue. What version of dash do you have installed? Also, have you seen [this thread](https://stackoverflow.com/questions/70705454/what-version-of-dash-is-needed-for-core-components-to-work)? – Jacek Jaskólski Mar 10 '22 at 22:19
  • Hmm. I was originally trying with 1.4.1 so I tried 1.14.0 and 1.19.0 and got the same error on all of them. Strangely enough, when I tried running the same program from a Jupyter cell, it did not get the import error, and instead got "zmq.error.ZMQError: Address already in use" which I constantly get, regardless of the port I set to use. – Sameer Mar 10 '22 at 22:40
  • 2
    If you're using dash 1.x then you need to import dcc (and html) separately: `import dash_core_components as dcc` and `import dash_html_components as html`. The current version of dash is 2.2.0. [dcc](https://pypi.org/project/dash-core-components/) (and [html](https://pypi.org/project/dash-html-components/)) are in the main dash repo as of dash 2 (Python >=3.6) – Jacek Jaskólski Mar 10 '22 at 23:07
  • I am facing the same issue. the import actually works when calling it in the python console, but I have the same error when trying to import it from a Jupyter Notebook. Did you solve the issue? – mStudent Apr 26 '22 at 07:30

2 Answers2

8

Either try: pip install dash --upgrade

or instead (for older versions): import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output

Hope this helps

Baz
  • 81
  • 3
0

Seems like this is the only thread for this specific problem. I ran the same code on Jupyter Notebooks only and never got an error. However when I opened the same notebook in VSCode it gave me the error. It also gave me an error for Flask. I resolved the error by downgrading my Python version to Python 3.9 - and magically I had no more import errors. My codeblock below for my imports. Uncomment the from dash-depencies and test:

import pandas as pd
import plotly.express as px  # (version 4.7.0 or higher)
import plotly.graph_objects as go
import dash_core_components as dcc
#from dash.dependencies import Input, Output
from dash import Dash, dcc, html, Input, Output
Barnez299
  • 25
  • 2
  • 4