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?
-
can you paste a minimal reproduciable code that led to so large installer? – Lei Yang Mar 22 '22 at 09:34
-
@LeiYang I have used sklearn library for Linear Regression. – Murtaza Zaidi Mar 22 '22 at 09:41
-
can you check the (compressed) directory size of sklearn library module? – Lei Yang Mar 22 '22 at 09:43
1 Answers
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.
- 317
- 4
- 7