python - ImportError:无法从“app”导入名称“app”
问题描述
我对 dash 还很陌生,我正在尝试遵循一些更高级的指南(链接:here),这些指南着眼于多页仪表板,但似乎在一路上遇到的每一个障碍都失败了。
我已经成功地创建了我的虚拟环境,安装了所需的包,并且我刚刚创建了“app.py”文件,但是当我创建并运行“index.py”文件时,我看到了以下错误:
ImportError: cannot import name 'app' from 'app'
我正在运行的 app.py 文件是使用以下代码创建的:
import dash
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
#app.config.suppress_callback_exceptions = True ####<-- tutorial said to run this line but as suppress was giving me errors I removed it
我正在运行的“index.py”文件如下所示:
from app import app
from app import server
import dash_html_components as html
import dash_core_components as dcc
app.layout = html.Div([html.H1('Dash Demo Graph',
style={
'textAlign': 'center',
"background": "yellow"}),
dcc.Graph(
id='graph-1',
figure={
'data': [
{'x': [1, 2, 3, 4, 5, 6, 7], 'y': [10, 20, 30, 40, 50, 60, 70], 'type': 'line', 'name': 'value1'},
{'x': [1, 2, 3, 4, 5, 6, 7], 'y': [12, 22, 36, 44, 49, 58, 73], 'type': 'line', 'name': 'value2'}
],
'layout': {
'title': 'Simple Line Graph',
}
}
),
], style={
"background": "#000080"}
)
if __name__ == '__main__':
app.run_server(debug=True)
我在使用 Jupyter Lab 和 python 3.8 的 Windows 机器上,运行代码的目录包含以下文件夹和文件:
.ipynb_checkpoints
__pycache__
env
app.py
index.py
任何有关我如何解决此错误的帮助将不胜感激。
解决方案
推荐阅读
- reactjs - React Redux:使用 Enzyme/Jest 测试 mapStateToProps 和 mapDispatchToProps
- javascript - 在 bbcode 标签之外的文本中添加标签
- php - 在 MAMP 4.4.1 PHP 7.2.1 上启用 SSH2
- abap - 如何动态调用字段符号
- java - 使用自定义类从 ArrayList 中搜索元素并为其更改颜色
- mysql - 部署 Qt MySql 应用程序
- ios - 如果从函数外部修改 inout 参数会改变吗?(迅速)
- redux - Redux thunk dispatch 不返回错误
- android - 找到多个文件,其独立于操作系统的路径为“lib/armeabi/libBugly.so”
- c# - C# 停止异步继承