I have a question I make an application using python. now I'm trying to make it executable. and I did it with the help of this . Now I'm facing a problem the python file size is in KB about 2kb and when i make exe of it the size 5MB
Asked
Active
Viewed 2,169 times
1
-
1remove unnecessarily library imports – Zabir Al Nazi Apr 27 '20 at 20:11
-
1The python script you are using likely imports several things. When you call import * at the top of your script, you are importing all that code into your script before you run it. When you create an .exe, it packages all those imports into your .exe file. You can reduce this by removing imports you haven't used as @ZabirAlNazi mentioned. You may also want to look at only importing specific parts of the library, instead of the entire library (where possible) – Sri Apr 27 '20 at 20:14
-
Why do you find it a problem that your output file size is so much different from the input's? If you add 6MB of comments to your Python code, the executable will be *smaller* than the source code. Would that be an acceptable solution? – Jongware Apr 27 '20 at 20:26
-
@usr2564301 I'm trying to say that is it worst case that the exe is more larger than .py file my python file is 2kb and exe is 5mb. mean it's lot of difference. what I was thinking that this will become approximately 1MB after making exe. – Osama Billah Apr 27 '20 at 20:31
-
1You want the exe to be able to run without installing python. The python installer is quite a lot bigger than 6MB, so whatever your expectation 6MB is pretty good to include the bits of python needed to execute your application. – DisappointedByUnaccountableMod Apr 27 '20 at 21:26
-
@barny thank you sir. – Osama Billah Apr 28 '20 at 19:15
-
1Cythonize your python file and then compile it using a C/C++ compiler. Use the 'cython' module and that leaves a '.c' file. Compile that with a C/C++ compiler. Cython Documentation at: https://cython.readthedocs.io/en/latest/src/quickstart/build.html – newbie09 Oct 07 '20 at 02:38
2 Answers
0
You can also use UPX
for those purposes.
UPX Download - https://github.com/upx/upx/releases/tag/v3.96
Use UPX with the module 'PyInstaller' for better results(somewhat).
PyInstaller Download - https://pypi.org/project/pyinstaller/ PyInstaller Documentation - https://pyinstaller.readthedocs.io/en/stable/
PyInstaller with UPX - https://pyinstaller.readthedocs.io/en/stable/usage.html?#using-upx

newb1
- 1
-
Hmm, I tested UPX with an exe of 294.1 MB and the result, using the `--best` compression option is 293.9 MB. – Guimoute Oct 22 '20 at 15:09