SoFunction
Updated on 2025-04-07

A super complete guide to using Python to package programs and make Windows installers

Preface

When you share it with users without a Python environment after developing a Python application, it is not convenient to directly distribute the source code. This article will teach you how to package Python scripts into Windows executables (.exe) and further make them into an installer with a setup wizard.

Step 1: Package Python scripts using auto-py-to-exe

auto-py-to-exeis a user-friendly tool for packaging Python scripts into standalone executables. The following are the detailed operations:

1.1 Install auto-py-to-exe

Run the following command to install in the command lineauto-py-to-exe

pip install auto-py-to-exe

1.2 Start the graphical interface

After the installation is completed, run the following command to startauto-py-to-exeGraphic interface:

auto-py-to-exe

1.3 Configuring Packaging Options

In the pop-up graphical interface:

  • Script Location: Select your Python script file (e.g.your_script.py)。
  • Onefile: Check "Onefile" to package all content into a single file.
  • Console Window
    • If it is a GUI program, select Window Based (hide the console).
    • If it is a command line program, select "Console Based".
  • Icon: Optional, if you need a custom icon, you can choose one.icodocument.

ClickConvert .py to .exe, waiting for the packaging to be completed. After the package is successful, the generated.exeThe file is usually located inoutputIn the folder.

1.4 Test generated .exe file

Found the generated.exeDouble-click to run the file to ensure that the program works normally. If everything is OK, you can move on to the next step.

Step 2: Create the installer using Inno Setup

In order to.exePack the file into an installable program (with installation wizard), we use special toolsInno Setup

2.1 Download and install Inno Setup

  • Go toInno Setup Official Download PageDownload the latest version.
  • Follow the prompts to complete the installation.

2.2 Create an installation script

  • Open Inno Setup and select“Create a new script file using the Script Wizard”

  • Follow the wizard to fill in the information:

    • Application Information:

      • Application name: Fill in the application name (such as "My App").
      • Application version: Fill in the version number (such as "1.0").
      • Application publisher: Fill in the publisher name (such as “My Company”).
    • Application Files:

      • Add generated.exeFiles, e.g.C:\Users\YourName\output\your_program.exe
    • Application Shortcuts:

      • Check "Create a shortcut for this application" and set the shortcut name.
    • Application Documentation:

      • Optional: If there is a license agreement file or help document, you can add it in this step.
    • Setup Languages:

      • The default is the English installation interface, and you can also choose another language.
    • Compiler Output:

      • Set the location where the installer is generated, for exampleC:\Users\YourName\output\
  • After completion, Inno Setup will generate a.issFile (script file).

2.3 Compile and install the program

  • Click on the top of the Inno Setup interface“Compile”button.
  • After compilation is completed, find the generated installer in the output directory (such as)。

Step 3: Test the installer

  • Run generated, follow the prompts to complete the installation.
  • Check the following:
    • Whether it is correctly installed in the specified directory (such asC:\Program Files\YourApp)。
    • Whether to generate a desktop shortcut.
    • Whether the program can run normally.

Additional Tips

Reduce packaged file size

If the packaged file is too large, you can try the following method:

  • existauto-py-to-exeEnable the "Advanced" option in   to manually exclude unwanted dependencies.
  • Make sure that only the actual required dependencies are installed.

Custom installation interface

Inno Setup supports highly customization and can be edited.issThe script adds background pictures, custom text, etc. of the installation interface.

Example: Add a background image to the installer:

[Setup]
WizardImageFile=path\to\your\
WizardSmallImageFile=path\to\your\small_image.bmp

More friendly user experience

  • Add program icon: inauto-py-to-exeand Inno Setup respectively specify icon files.
  • Added uninstall function: Inno Setup generates an uninstaller by default, and users can remove the software through the control panel.

Summarize

Through the guidance of this article, you can easily package Python scripts into separate executables and create a complete installer for easy installation and use. Here are the core steps:

  • useauto-py-to-exePackage Python scripts as.exedocument.
  • Use Inno Setup to create the installer.
  • Test whether the packaged program is running normally.

This is the article about using Python to package programs and making Windows installers. For more related content on Python packaging and making Windows installers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!