0

N.B.: Please do not lock/delete this question as I did not find any relevant answer.

I need to convert a .py file to .exe. I have tried pyinstaller, py2exe, and auto_py_to_exe. Unfortunately, the output files are very big. For example, if I simply convert a python file to print('Hello world!'), the output folder becomes 22 MB. The command of --exclude-module does not reduce so much. If I write the same code in C and compiled by Dev-C++, the file size will be below 1 MB.

So, is there any way to convert the .py file to a .exe file with a smaller file size?

  • 3
    PyInstaller will bundle everything that is necessary to run your program, in this case the standard libraries and the interpreter. If you do not want to do that, you need to ensure that on the target machine the requirements (i.e. a Python interpreter) are installed, and run the script directly. There is no way around one way or the other. C code on the other hand is compiled and linked to a platform-specific binary, which only includes the machine code instructions. – Jan Christoph Terasa Feb 14 '21 at 05:44
  • 1
    See options to reduce pyinstaller size here: https://stackoverflow.com/questions/47692213/reducing-size-of-pyinstaller-exe – zvi Feb 14 '21 at 07:47
  • @JanChristophTerasa Thank you for your comments. I understand it now. – King D Anonymous Feb 14 '21 at 17:48
  • @zvi Thank you, I have already checked that link. – King D Anonymous Feb 14 '21 at 17:49

1 Answers1

2

As mentioned by Jan in the comments, pyinstaller bundles everything together that is needed to run the program. So realistically the only to make the file smaller is to make sure the target computer has a python environment. Long story short, if you must use a .exe then they are not going to get any smaller unless you re-write it so it needs less external libraries etc.