python-3.x - 使用 pyinstaller 实用程序打包仪表板(在仪表板上)的问题
问题描述
各位同事,帮我处理一下出现的问题。有必要展示我在硬件上创建的仪表板,其中无法安装 Python 及其库。为此,我不得不使用 Pyinstaller。我将根据我创建仪表板的仪表板示例展示问题的本质。我的仪表板和示例仪表板都在工作,但是在使用pyinstaller --onefile example.py
命令打包并example.exe
在正在运行的程序的控制台中运行后,它给出了一个错误:
Traceback (most recent call last):
File "I:\Docs\BI\Devtest\example.py", line 139, in <module>
app.run_server(debug=True, port=8000)
File "dash\dash.py", line 1675, in run_server
File "dash\dash.py", line 1447, in enable_dev_tools
File "dash\dash.py", line 1450, in <listcomp>
AttributeError: 'FrozenImproter' object has no attribute 'filename'
[11876] Failed to execute script 'example' due to unhandled exception!
在互联网上搜索这个问题并没有给出积极的结果(关于基于 的应用程序dash_bootstrap_components
)。非常感谢您的帮助...仪表板示例的源代码:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, Input
import plotly.express as px
import dash_bootstrap_components as dbc
import pandas as pd
import pandas_datareader.data as web
import datetime
# https://stooq.com/
start = datetime.datetime(2020, 1, 1)
end = datetime.datetime(2020, 12, 3)
df = web.DataReader(['AMZN','GOOGL','FB','PFE','MRNA','BNTX'],
'stooq', start=start, end=end)
# df=df.melt(ignore_index=False, value_name="price").reset_index()
df = df.stack().reset_index()
print(df[:15])
# df.to_csv("mystocks.csv", index=False)
# df = pd.read_csv("mystocks.csv")
# print(df[:15])
# https://www.bootstrapcdn.com/bootswatch/
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP],
meta_tags=[{'name': 'viewport',
'content': 'width=device-width, initial-scale=1.0'}]
)
# Layout section: Bootstrap (https://hackerthemes.com/bootstrap-cheatsheet/)
# ************************************************************************
app.layout = dbc.Container([
dbc.Row(
dbc.Col(html.H1("Stock Market Dashboard",
className='text-center text-primary mb-4'),
width=12)
),
dbc.Row([
dbc.Col([
dcc.Dropdown(id='my-dpdn', multi=False, value='AMZN',
options=[{'label':x, 'value':x}
for x in sorted(df['Symbols'].unique())],
),
dcc.Graph(id='line-fig', figure={})
],# width={'size':5, 'offset':1, 'order':1},
xs=12, sm=12, md=12, lg=5, xl=5
),
dbc.Col([
dcc.Dropdown(id='my-dpdn2', multi=True, value=['PFE','BNTX'],
options=[{'label':x, 'value':x}
for x in sorted(df['Symbols'].unique())],
),
dcc.Graph(id='line-fig2', figure={})
], #width={'size':5, 'offset':0, 'order':2},
xs=12, sm=12, md=12, lg=5, xl=5
),
], no_gutters=True, justify='start'), # Horizontal:start,center,end,between,around
dbc.Row([
dbc.Col([
html.P("Select Company Stock:",
style={"textDecoration": "underline"}),
dcc.Checklist(id='my-checklist', value=['FB', 'GOOGL', 'AMZN'],
options=[{'label':x, 'value':x}
for x in sorted(df['Symbols'].unique())],
labelClassName="mr-3"),
dcc.Graph(id='my-hist', figure={}),
], #width={'size':5, 'offset':1},
xs=12, sm=12, md=12, lg=5, xl=5
),
dbc.Col([
dbc.Card(
[
dbc.CardBody(
html.P(
"We're better together. Help each other out!",
className="card-text")
),
dbc.CardImg(
src="https://media.giphy.com/media/Ll0jnPa6IS8eI/giphy.gif",
bottom=True),
],
style={"width": "24rem"},
)
], #width={'size':5, 'offset':1},
xs=12, sm=12, md=12, lg=5, xl=5
)
], align="center") # Vertical: start, center, end
], fluid=True)
# Callback section: connecting the components
# ************************************************************************
# Line chart - Single
@app.callback(
Output('line-fig', 'figure'),
Input('my-dpdn', 'value')
)
def update_graph(stock_slctd):
dff = df[df['Symbols']==stock_slctd]
figln = px.line(dff, x='Date', y='High')
return figln
# Line chart - multiple
@app.callback(
Output('line-fig2', 'figure'),
Input('my-dpdn2', 'value')
)
def update_graph(stock_slctd):
dff = df[df['Symbols'].isin(stock_slctd)]
figln2 = px.line(dff, x='Date', y='Open', color='Symbols')
return figln2
# Histogram
@app.callback(
Output('my-hist', 'figure'),
Input('my-checklist', 'value')
)
def update_graph(stock_slctd):
dff = df[df['Symbols'].isin(stock_slctd)]
dff = dff[dff['Date']=='2020-12-03']
fighist = px.histogram(dff, x='Symbols', y='Close')
return fighist
if __name__=='__main__':
app.run_server(debug=True, port=8000)
解决方案
推荐阅读
- javascript - 使用 JavaScript 解析完整的 HTML 块
- javascript - 如何准确更新firebase web上的字段
- c++ - 禁止函数的返回引用被赋值覆盖
- java - 错误 --> java.sql.SQLException: 索引处缺少 IN 或 OUT 参数:: 21
- python - 如何列出一组单词?
- npm - NPM --proxy 选项有效,但在配置中设置代理无效
- java - 使用 FlaotBridge 进行范围查询的 Hibernate Search
- typescript - mongoose.save() 不保存它的数据
- spring - Spring AOPed 目标类不注入模拟
- swift - swift项目范围,如何将地址转换为自定义类?