How to make executables with cx_freeze and how reduce size of the generated executable

Viewed 1824

I made a python script and now I want to make it's executable with cx_freeze. It's first time for me.

My code:

    from cx_Freeze import setup, Executable


build_exe_options = {'packages': ['pandas','os']}


setup(
    name = "monprog",
    version = "0.1",
    options = {"build_exe": build_exe_options},
    description = "Convert_program",
    executables = [Executable("test.py")],
)

It works but my files are too big (2GB). A lot of library files are imported (150 - 200 library) into the executable helpers.

My program is very simple, there are 2 imports (pandas and os) and 50 lines of code. Maybe an error with "options" argument ?

How to reduce the program size?

Thank `

PS: I use anaconda platform

2 Answers

I succes.

I create new anaconda environment with a minimum packages (only pandas and cx_freeze). Then I compiled with cx_freeze.

Before, my folder does 2go, now only 280 mo.

However, for export on a other machine, I had to add mkl*.dll in my folder . these dll are located in anaconda files On my PC : D:\anaconda\pkgs\mkl-2020.0-166\Library\bin

Copy all mkl*.dll and libiomp5md.dll.

For avoid a error import : mkl_intel_thread.dll

Taken verbatim from here:

Part of the purpose of cx_Freeze is to bundle all the dependencies, so that the end user need not install them. numpy, matplotlib, etc. are not small dependencies, especially because they have large binary (non-Python) components. So what you are asking is not physically possible, not because of cx_Freeze limitations, but because of a contradiction between the following two requirements:

  • end user should be able to run executable on essentially any Windows machine, including possibly one without Python, numpy, and matplotlib
  • distributed binary size should be small

You cannot satisfy both these requirements simultaneously. cx_Freeze is appropriate for the first, but not the second. If you can assume your end users already have Python, numpy, matplotlib installed (or can install seperately), and want to distribute your program such that the binary size be small, a wheel is more appropriate.

Related