Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Pyinstaller executable doesn't work if I move the dependency

So I created an exe file using pyinstaller and gave it an icon as well using -i my_icon.ico and the executable works well but if I delete my_icon.ico or move it from it's current directory, it stops working?? Any solution to this so that the executable will work even without the dependency


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

1 Answer

0 votes
by (71.8m points)

After your first run of pyinstaller, a .spec file is created, which you can modify. Then on your next call to pyinstaller, instead of pointing to your .py script, point to the .spec file instead.

Then you are able to make modifications to the spec file, where you can add the following line afer the Analysis call to compile any data files into your .exe. Insert the appropriate path and name of your icon

a.datas += [('name_of_icon.ico', 'path_to_icon\name_of_icon.ico', 'Data')]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...