1

I have converted python file to exe using this But the size of .exe is 800mb, is there any way I can reduce its size?

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

2

Using Pyinstaller

The --onefile flag with pyinstaller (e.g., pyinstaller myprogram.py --onefile or pyinstaller myprogram.py -F puts everything in just a single executable, including all the code of all your installed dependencies, even if you're using just one function from them. That's a lot!

The --onedir or -D flag instead puts the those dependencies in a directory that's packaged alongside your compiled code. It tends to reduce the size of the .exe file considerably.

But still, I wouldn't recommend using Pyinstaller. Having experimented with it extensively, I've found that execution time is incredibly slow on machines that don't already have a Python-friendly environment. (Most of the slow execution time comes from loading those dependencies.)

Using cx_Freeze

For the executables that I build for my department, I use cx_Freeze to build an installer or a disk image.

To do so, all you have to do is write a setup script and then call py setup.py bdist_msi (Windows) or py setup.py dbist_dmg (Linux).

The resulting installer will be relatively small and, once it's installed, it will execute much faster than any of the Pyinstaller options I've seen.

Jeff Martin
  • 317
  • 4
  • 7