Search code examples
python-3.xcx-freeze

[cx_Freeze Q]: How to build MSI from non-standard build directory?


I'm trying to get my build-process to build from a non-standard build directory. Project stored in c:\users\user\onedrive\dev\project. And these are my build-options in setup.py:

build_options = {
    'packages': ["pyfiglet"],
    'excludes': ["scipy", "PIL", "tkinter", "test"],
    # use this temp dir, so onedrive does not go crazy and lock files!
    'build_exe': f"c:/Temp/{DESCRIPTION.replace(' ','_')}-build", 
}

But now I struggle to define the bdist_msi_options block:

bdist_msi_options = {
    'upgrade_code': '{1}',
    'add_to_path': False,
    'install_icon': 'icon.ico',
    'skip_build': True, # so I can sign the exe before MSI'ing
    'initial_target_dir': r'[ProgramFilesFolder]\{0}\{1}'.format(
        COMPANY, DESCRIPTION),
}

I don't see any option to define that the MSI-build would take the pre-built .exe from c:\temp\.

And finally the main():

executables = [
    Executable(
        SCRIPT_FILE, # something.py
        base='Console',
        target_name=OUT_FILENAME,
        copyright=COPYRIGHT,
        icon="icon.ico",
        shortcut_name=DESCRIPTION,
        shortcut_dir="DesktopFolder",
    )
]

setup(name='HeightStorage',
      version=cfg.version,
      description=LONG_DESCRIPTION,
      options={
          'build_exe': build_options,
          'bdist_msi': bdist_msi_options,
      },
      executables=executables)

Any hints are appreciated.


Solution

  • Try to set the build directory in the build options as well and to use the bdist_dir option of the bdist_msi options:

    build_dir = f"c:/Temp/{DESCRIPTION.replace(' ','_')}-build"  # or whatever you like
    bdist_dir = build_dir  # define here a new directory if you want to keep build_dir
    build_options = {
        ...
        'build_exe': build_dir,
    }
    bdist_msi_options = {
        ...
        'bdist_dir': bdist_dir,    
    }
    setup(
        ...
        options={
            'build': {'build_exe': build_dir},
            'build_exe': build_options,
            'bdist_msi': bdist_msi_options,
        },
        ...
    }