Search code examples
pythoncx-freeze

Error in opening Python executable file, created using cx_freeze


Before asking this question have checked other queries (cx_freeze ImportError when executing file) was related to my issue, error was "DLL load failed" but my case is "No module named".
My question is - I have created a Python executables using cx_freeze but when I open the Main.exe file, the application opens with Traceback errors on it..

    import sys
    from cx_Freeze import setup, Executable

    # Dependencies are automatically detected, but it might need fine tuning.
    build_exe_options = {
        "optimize": 2,
        "includes": [],
        "compressed": True,
        "copy_dependent_files": True,
        "create_shared_zip": False,
        "append_script_to_exe": True,
        "include_in_shared_zip": False,

        "include_files":[('vPlot.ui'),
                         ('vPlot.py'),
                         ('company.jpg')], 
        "include_msvcr": True,
        "packages": [],
    }

    # GUI applications require a different base on Windows (the default is for a
    # console application).
    base = None
    if sys.platform == "win32":
       base = "Win32GUI"

    setup(  name = "plcTest",
            description = "plcTest!",
            options = {"build_exe": build_exe_options},
            executables = [Executable("Main.py",
                                      base=base,
                                      copyDependentFiles=True,
                                      appendScriptToExe=True)])

my error is (https://i.sstatic.net/w1oLc.png), I can't find the file "'matplotlib.backends.backend_tkagg'", please give your advise, thanks in advance


Solution

  • cx-freeze have good module analysis but sometimes it is fails. Especially back and modules.

    Matplotlib uses tkagg (i am not sure it is package name)as backend gui module. To solve this, you have two options;

    1- import missing package somewhere in your code

    2- pass package name to cx-freeze as parameter.

    Example: i used cx-freeze from command-line

    cxfreeze FooMain.py --include-module=simplejson, lxml  # FooMain.py my main script
    

    edit: using python build_exe_options

    "packages": ["simplejson", "lxml"],