Plotly/dash - 模块 'dash_html_components' 没有 'Div' 成员

Plotly/dash - Module 'dash_html_components' has no 'Div' member

我想要 运行 来自 plotly 的这段代码。
之前,我安装了这些模块:

pip install dash==0.21.1  # The core dash backend
pip install dash-renderer==0.13.0  # The dash front-end
pip install dash-html-components==0.11.0  # HTML components
pip install dash-core-components==0.23.0  # Supercharged components
pip install plotly --upgrade  # Latest Plotly graphing library

我的代码是:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

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(debug=True)

但是它不起作用,我不明白为什么! 你能帮我吗 !谢谢

python3可以执行代码。

我的包版本是:

dash==0.21.1
dash-core-components==0.23.0
dash-html-components==0.11.0
dash-renderer==0.13.0
plotly==2.7.0

结果:

我知道这是一个老问题,但我最近 运行 遇到了这个错误,之前的回答没有帮助。

经过进一步探索,出现此错误的原因是软件包 dash_html_components 已被弃用。

解决方法: 替换 import dash_core_components as dcc from dash import dcc

此外,现在已弃用的其他类似包是 dash_html_components