You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3.4版Spyder中运行Dash简易仪表盘时初始化报错求助

Hey there, let's work through the issues you're hitting with your Dash app in Python 3.4 and Spyder. I spot a couple of key problems right away:

1. Your code has incomplete syntax

Looking at the snippet you shared, there are unclosed brackets and truncated data in your dcc.Graph figure. That's definitely throwing errors. Here's a fixed, complete version of your code:

import dash
import dash_core_components as dcc
import dash_html_components as html

# Adding __name__ helps avoid issues when deploying later
app = dash.Dash(__name__)  

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': 'San Francisco'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    # Run the server with debug mode for easier testing
    app.run_server(debug=True)

2. Python 3.4 is way too old for modern Dash

Python 3.4 reached end-of-life back in 2019, and almost all recent Dash versions drop support for it. This is probably a big reason your app is failing even if you fix the syntax.

  • Best fix: Upgrade your Python version to 3.7 or newer (3.8-3.11 are the most stable for Dash right now). This will let you use the latest Dash features and avoid compatibility headaches.
  • If you must stick with 3.4: Install older, compatible versions of the Dash packages with this command:
pip install dash==1.21.0 dash-core-components==1.17.1 dash-html-components==1.1.4

3. Spyder-specific quirks to watch for

When running Dash apps in Spyder, sometimes the automatic browser pop-up doesn't work. Try these:

  • Check Spyder's IPython console settings: Go to Tools > Preferences > IPython console > Graphics and set the backend to something other than "Inline" (like "Qt5").
  • After running your code, look for the local server URL in the console (usually http://127.0.0.1:8050/) and manually paste it into your browser—this works more reliably than relying on Spyder to open it for you.

内容的提问来源于stack exchange,提问作者Matt W.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:23:32