Nuitka-Action

repository·main·Indexed 42 days ago

https://github.com/nuitka/nuitka-action

A GitHub Action that automates the compilation of Python scripts into standalone executables or binary modules across Windows, macOS, and Linux using the Nuitka compiler. It supports building GUI applications with plugins like pyside6 and tk-inter, multi-platform builds via matrix strategies, and configuration for build modes such as 'app' and 'module'.

Tokens
1.4K
Snippets
4
Records
5
Agent score
4%

What's inside Nuitka-Action

  1. Specify multiple values for Nuitka options

    main

    Since GitHub Actions does not support list values for input parameters, you can provide multiple values for Nuitka options (like include-data-dir) by separating them with newlines. Each line should follow the source=destination format.

    include-data-dir: |
      source_path_dir1=dest_path_dir1
      source_path_dir2=dest_path_dir2
      source_path_dir3=dest_path_dir3
  2. Build a standalone Python executable with Nuitka-Action

    main

    Use Nuitka/Nuitka-Action@main in your GitHub Actions workflow to compile Python scripts into standalone executables (*.exe, *.bin, or .app bundles).

    Key Configuration:

    • script-name: The path to your Python script.
    • nuitka-version: The version of Nuitka to use (e.g., main).
    • mode: Determines the build type. The default is app. Use module when building binary Python modules (*.pyd).
    - uses: Nuitka/Nuitka-Action@main
      with:
        nuitka-version: main
        script-name: hello_world.py
  3. Perform multi-platform builds using a matrix strategy

    main

    You can build for Windows, macOS, and Linux simultaneously by using a GitHub Actions matrix strategy. This allows you to run the same compilation steps across different runs-on operating systems.

    Recommended Workflow Steps:

    1. actions/checkout@v4 to get your code.
    2. actions/setup-python@v5 to prepare the environment.
    3. Install your project dependencies via pip.
    4. Run Nuitka/Nuitka-Action@main to build the executable.
    5. actions/upload-artifact@v4 to save the resulting binaries. Note: Always set include-hidden-files: true when uploading artifacts to ensure .libs folders and other necessary hidden files are included.
    jobs:
      build:
        strategy:
          matrix:
            os: [macos-latest, ubuntu-latest, windows-latest]
    
        runs-on: ${{ matrix.os }}
    
        steps:
          - name: Check-out repository
            uses: actions/checkout@v4
    
          - name: Setup Python
            uses: actions/setup-python@v5
            with:
              python-version: '3.10'
              architecture: 'x64'
              cache: 'pip'
              cache-dependency-path: |
                **/requirements*.txt
    
          - name: Install Dependencies
            run: |
              pip install -r requirements.txt -r requirements-dev.txt
    
          - name: Build Executable
            uses: Nuitka/Nuitka-Action@main
            with:
              nuitka-version: main
              script-name: your_script.py
              mode: app
    
          - name: Upload Artifacts
            uses: actions/upload-artifact@v4
            with:
              name: ${{ runner.os }} Build
              path: |
                build/*.exe
                build/*.bin
                build/*.app/**/*
                build/*.dist/**/*
              include-hidden-files: true
  4. Compile GUI applications with PySide6 or Tkinter

    main

    To ensure GUI frameworks are correctly included in your compiled application, use the enable-plugins option. This is required for frameworks like PySide6 and Tkinter to function in a standalone environment.

    Supported Plugins mentioned:

    • pyside6
    • tk-inter
    # Qt GUI with PySide6
    - name: Qt GUI with PySide6
      uses: Nuitka/Nuitka-Action@main
      with:
        nuitka-version: main
        script-name: my_qt_gui_app.py
        mode: standalone
        enable-plugins: pyside6
    
    # Python GUI With TkInter
    - name: Python GUI With TkInter
      uses: Nuitka/Nuitka-Action@main
      with:
        nuitka-version: main
        script-name: my_tkinter_gui_app.py
        mode: standalone
        enable-plugins: tk-inter
  5. Common pitfalls and troubleshooting

    main

    When using Nuitka-Action, be aware of the following:

    • Incomplete Artifacts: When using actions/upload-artifact, you MUST set include-hidden-files: true. If omitted, critical directories like .libs may be excluded, causing the executable to fail.
    • Incorrect Mode: The default mode is app. If you are trying to build binary Python modules (*.pyd), you must explicitly set mode: module.
    • License Compliance: Nuitka compiles your project along with its dependencies into a single executable. This creates a derivative work. You are responsible for ensuring your project complies with the licenses of all included dependencies.