Pyinstaller - getting multiple exe files in a single compilation

Viewed 185

I wanted to have multiple .exe files with common used libraries. for example, I have a project that should have a.py and b.py and both these scripts use another script like c.py so I should have a.exe and b.exe.

curently i can get this like this:

pyinstaller a.py

and then

pyinstaller b.py

and after that copy contents of dist\a to dist\b and replace them so I will have both a.exe and b.exe in the same place without duplication of other compiled libraries. Is there a way to do this with a single command like pyinstaller a.py,b.py?

1 Answers

I just solved this problem that was bothering me.

you can make some .spec file and merge them, and run pyinstaller to build multi exe.

  • generate a spec file for each python file that you want build to exe.
pyi-makespec xxx.py

generated .spec file just like this:

a = Analysis(...)
pyz = PYZ(a.pure, a.zipped_data, ...)
exe = EXE(pyz,a.scripts, ...)
coll = COLLECT(exe,a.binaries, ...)
  • change variable name, just like this:
main = Analysis(...)
main_pyz = PYZ(main.pure, main.zipped_data, ...)
main_exe = EXE(main_pyz,main.scripts, ...)
coll = COLLECT(main_exe,main.binaries, ...)
  • process all .spec files like this and merge the contents of coll into one
main = Analysis(...)
main_pyz = PYZ(main.pure, main.zipped_data, ...)
main_exe = EXE(main_pyz, main.scripts, ...)
sub = Analysis(...)
sub_pyz = PYZ(sub.pure, sub.zipped_data, ...)
sub_exe = EXE(sub_pyz, sub.scripts, ...)
...
coll = COLLECT(main_exe, sub_exe, ...)
  • finally, build it with the pyinstaller
pyinstller xxx.spec
Related