pythongitlab-cicx-freezegitlab-ci.yml

Invalid command 'bdist_msi' when trying to create MSI installer with 'cx_Freeze' in Gitlab CI/CD Pipeline


I'm using py setup.py bdist_msi to generate windows single executable file for my python application. this works fine on my computer, but it does not work when it is executed in GitLab pipeline. does anyone know how to solve this issue? i'm using Python 3.11.8 on my local machine and on the pipeline. here is the error: enter image description here

here is my setup.py file:

from cx_Freeze import setup, Executable
import sys



directory_table = [("ProgramMenuFolder", "TARGETDIR", "."),
                   ("MyProgramMenu", "ProgramMenuFolder", "MYPROG~1|My Program")]

msi_data = {"Directory": directory_table,
            "ProgId": [("Prog.Id", None, None, "This is a description", "IconId", None)],
            "Icon": [("IconId", "matplotlib.ico")]}
files = ['param_list.py', 'mca_ioconfig_parser.py', 'mca_package_manifest_parser.py', 'mca_rti_log_parser.py',
         'ui_interface.py', 'resources_rc.py']
bdist_msi_options = {"add_to_path": False,
                     "data": msi_data,
                     'initial_target_dir': r'[ProgramFilesFolder]%s' % 'yammiX',
                     "upgrade_code": "{96a85bac-52af-4019-9e94-3afcc9e1ad0c}"}

build_exe_options = {"excludes": [], "includes": []}
executables = Executable(script="toolName.py",
                         base="Win32GUI" if sys.platform == "win32" else None,
                         icon="matplotlib.ico",
                         shortcut_name="toolName",
                         shortcut_dir="DesktopFolder")
setup(name="toolName",
      version="0.1.5",
      author="toolName",
      description="",
      executables=[executables],
      options={"build_exe": build_exe_options,
               "bdist_msi": bdist_msi_options})

here is my yml file:

image: python:3.11.8
stages:
  - build
  - test
  - deploy

build-job:
  stage: build
  # Update stuff before building versions
  before_script:
    - apt-get update -q -y
    - apt install -y python3-pip
    - apt install -y python3-venv
    - python3 -m venv .venv
    - source .venv/bin/activate
    - python3 --version
    - python3 -m pip install -r requirements.txt
  script:
    - python3 setup.py -q bdist_msi

  artifacts:
    paths:
      - build/

unit-test-job:
  stage: test
  script:
    - echo "Running unit tests... This will take about few seconds."
    - echo "Code coverage is 100%"

deploy-job:
  stage: deploy
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."

Solution

  • The bdist_msi option requires a Windows system. Your job is using Linux.

    See the cx_Freeze docuemtnation which states (emphasis added):

    On Windows, you can build a simple installer containing all the files cx_Freeze includes for your application, by running the setup script as:
    python setup.py bdist_msi

    cx_Freeze does not support cross-compilation. So, you will want to run this on a Windows GitLab runner in order to create a Windows setup file using cx_Freeze

    If you are using gitlab.com, you can use the SaaS Hosted Windows Runners.