VSCode dash app.run_server(debug=True) 不起作用 - 运行但显示“没有名为 <file name> 的模块”并且不加载

问题描述 投票:0回答:3

debug=True 在 VSCode 中不起作用。当我尝试运行它时,出现此错误:

> Dash is running on http://127.0.0.1:8050/
> 
>  * Serving Flask app 'Test' (lazy loading)  * Environment: production 
> WARNING: This is a development server. Do not use it in a production
> deployment.    Use a production WSGI server instead.  * Debug mode: on
> No module named Test

Test 是文件的名称 - 如果我将其更改为其他名称,例如 app.py 或 main.py,它只是这么说。

代码本身非常简单,直接取自 Plotly Dash 教程网站,https://dash.plotly.com/layout:

from dash import Dash, html, dcc 
import plotly.express as px
import pandas as pd

app = Dash(__name__)

# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
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)

如果我关闭调试,它会在新的浏览器窗口中打开仪表板。 Debug=True 过去也对我有用(好吧,调试没有,但当我重新加载时,仪表板已在浏览器中打开),唯一改变的是我现在使用 Azure DevOps 作为回购,但我不明白为什么这会有所作为?

有什么想法吗?

python visual-studio-code plotly-dash
3个回答
1
投票

当我包含

debug=True
并且 使用 VSCode 的调试器运行应用程序时,我遇到了同样的问题。

但是,我能够通过终端正常运行我的应用程序

> python app.py

并没有真正解决它,因为我还没有找到一种方法来正确调试我的应用程序,但我猜是一个解决方法。


0
投票

打开 VSCode 编辑器时,打开

test.py
文件所在的文件夹。 如果您需要使用我使用的父文件夹中的模块:

import sys 
sys.path.append('path_to_parent_folder')

然后运行调试器。


0
投票

我在将

cwd
参数添加到 launch.json 后修复了它。它应该等于
"${workspaceFolder}/RELATIVE_PATH_APP_FOLDER"
,其中
RELATIVE_PATH_APP_FOLDER
是工作区文件夹中 app.py 脚本的相对路径。

© www.soinside.com 2019 - 2024. All rights reserved.