Search code examples
pythoncx-freeze

How to disable cx_freeze to autodetect all modules


cx_freeze build includes all modules, that installed on my machine, so freezed build becomes a huge. How to disable autodetection feature? I just want to build small PyQt application:

import sys
from cx_Freeze import setup, Executable

path = sys.path + ["app"]
includes = ["app.core", "app.utils"]
excludes = ["tcl"]
build_exe_options = {
"path": path,
"icon": "resources\icons\clock.ico"}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "app",
        version = "1.1",
        description = "My Application",
        options = {"build_exe": build_exe_options},
        executables = [Executable("app.py", base=base,
            targetName="app.exe",
            shortcutName="Application",
            shortcutDir="DesktopFolder")])

Also I have the my custom modules, each has a utils submodule, so cx_freeze put wrong module.

How can I set strict list of modules, which i need?


Solution

  • It was quite simple. This application uses a custom modules, so I've added application folder to the path:

    path = sys.path + ["app"]
    

    The trick is that app uses module "utils" and I have other "utils" module in my OS path. Other "utils" module imports a lot of stuff like matplotlib, PIL, etc. So I've solved problem by changing path environment like this:

    path = ["app"] + sys.path
    

    So, cx_freeze gets right modules when freeze executable.