I am using Pyinstaller to convert a python script to an executable, the script contains multiple imports from various packages like nltk,begin,json and four more. The resulting executable file for a 10 line code is 54MB which is unrealistically high, I know it packages all modules in a single file , but does it make it so large as the python script itself is only 2KB.
What are some general tips to reduce the ".exe" file size?
I am using the command below to convert the script
>pyinstaller.py -F -o output check.py
I have only imported individual functions and not entire modules, like:
from nltk.metrics.agreement import AnnotationTask
The imported modules have independent functions and I have selectively imported only 3-4 functions , but this does not seem to have any effect on the generated exe file size, do all functions wastefully get imported in the exe file? How to avoid this?
You are comparing two totally different things, the exe file you generate does not only contain your file but also the Python interpreter and all imported modules. Looking at my python 2.7 install under windows I see that it is 83 MB large. ntlk and co probably aren't the smallest libraries either and you have to include all of them in the executable one way or the other. For comparison a medium-smallish project of mine generates about 23 MB using cx_freeze (and that includes 10 MB of QT4 dlls), so you could try that.
Also you can compress the executable using UPX, as described here which may help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With