Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

python - pyinstaller --onefile takes much longer than --onedir (plotly/dash)

I know that --onefile is supposed to take longer than --onedir, but I'm not sure if it's to this extent.

The code I'm compiling is very basic

# pyinstaller --onedir --noconfirm --additional-hooks-dir=hooks --paths=venvLibsite-packages script_min.py
# pyinstaller --onedir --noconfirm --additional-hooks-dir=hooks --paths=venvLibsite-packages script_min.py
# pyinstaller --onedir --clean --additional-hooks-dir=hooks script_min.py
import dash
import plotly.graph_objs as go
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server

labels = ["Oxygen", "Hydrogen", "Carbon_Dioxide", "Nitrogen"]
values = [4500, 2500, 1053, 500]
pie_fig = go.Figure(
    data=[go.Pie(labels=labels, values=values)]
)
piechart = dcc.Graph(
    figure=pie_fig
)

app.layout = html.Div([html.Div([piechart], className="row")])

if __name__ == "__main__":
    app.run_server(debug=False)

Subsequently, I added the hooks as necessary in a folder

enter image description here

When I compile as --onedir with pyinstaller --onedir --clean --additional-hooks-dir=hooks script_min.py, the .exe in the directory runs in less than a second.

But when i compile as --onefile with pyinstaller --onefile --clean --additional-hooks-dir=hooks script_min.py, it takes over 5 minutes to run.

I'm pretty sure it shouldn't take this long, as I reference a similar (and even more complicated) project here, for which its --onefile .exe runs in less than 10 seconds.

Whether I'm using hooks, or adding through datas/hidden-imports, the discrepancy is still present.

question from:https://stackoverflow.com/questions/65623447/pyinstaller-onefile-takes-much-longer-than-onedir-plotly-dash

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...