Search code examples
pythonpython-3.xpysidedistutilscx-freeze

Creating MSI with cx_freeze and bdist_msi for PySide app


I have a PySide application that I'm trying to package into an MSI using cx_freeze. I can successfully create an MSI installer, but I'm having trouble figuring out how to list additional modules to be included in the package. Here's my setup.py script:

import sys
from cx_Freeze import setup, Executable

company_name = 'My Company Name'
product_name = 'My Gui'

bdist_msi_options = {
    'upgrade_code': '{66620F3A-DC3A-11E2-B341-002219E9B01E}',
    'add_to_path': False,
    'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name),
    # 'includes': ['atexit', 'PySide.QtNetwork'], # <-- this causes error
    }

# GUI applications require a different base on Windows
base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

exe = Executable(script='MyGui.py',
                 base=base,
                 icon='MyGui.ico',
                )

setup(name=product_name,
      version='1.0.0',
      description='blah',
      executables=[exe],
      options={'bdist_msi': bdist_msi_options})

I can successfully create an MSI using the command

python setup.py bdist_msi

But according to the documentation for packaging PySide applications, I need to include the modules atexit and PySide.QtNetwork. I tried to do this by adding the 'includes' key to bdist_msi_options, but uncommenting that line causes the following error:

running bdist_msi
error: error in setup script: command 'bdist_msi' has no such option 'includes'

How do I get those modules to be included along with the generated executable?


Solution

  • I posted the same question on the cx-freeze mailing list, and received an answer.

    The 'includes' and 'packages' options are for the 'build_exe' command, so the call to setup needs to include both commands.

    bdist_msi_options = {
        'upgrade_code': '{66620F3A-DC3A-11E2-B341-002219E9B01E}',
        'add_to_path': False,
        'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name),
        }
    
    build_exe_options = {
        'includes': ['atexit', 'PySide.QtNetwork'],
        }
    
    ...
    
    setup(name=product_name,
          version='1.0.0',
          description='blah',
          executables=[exe],
          options={
              'bdist_msi': bdist_msi_options,
              'build_exe': build_exe_options})