Summary: in this tutorial, you’ll learn how to convert a PyQt application to an executable program (EXE) on Windows
We’ll convert the Editor program to an executable file on Windows using PyInstaller. The following shows the directory structure of the Editor program:
├── assets
| ├── editor.png
| ├── exit.png
| ├── new.png
| ├── open.png
| ├── redo.png
| ├── save.png
| └── undo.png
└── main.py
Code language: plaintext (plaintext)In this project:
- The
assetsdirectory stores all the images used by the program. - The
main.pystores the program source code.
First, activate the virtual environment where the PyQt program runs.
Note that if you don’t use a virtual environment, PyInstaller may create an output with a big size that include all packages installed.
Second, use the following pip command to install PyInstaller:
pip install pyinstallerCode language: plaintext (plaintext)PyInstall has a lot of options that are listed on this page. However, in this tutorial, we’ll show you the most commonly used ones.
Third, use the following pyinstaller command to convert the Editor program to an executable file:
pyinstaller main.py --noconsole --add-data "assets;assets" --icon="assets/editor.png" --name editor --noconfirmCode language: plaintext (plaintext)Once you run this command successfully, you’ll see that PyInstaller creates new directories and files including build, dist, and editor.spec:
├── assets
| ├── editor.png
| ├── exit.png
| ├── new.png
| ├── open.png
| ├── redo.png
| ├── save.png
| └── undo.png
├── build
| └── editor
├── dist
| └── editor
├── editor.spec
└── main.py
directory: 5 file: 9Code language: plaintext (plaintext)Inside the dist/editor directory, you’ll find the editor.exe file. To launch the program, you can double-click it:

How the pyinstaller command works:
--noconsoleoption hides the console window when the program launches.--add-data "assets;assets"option copies theassetsdirectory to thedist/editordirectory so that the program can reference the images and display them correctly. The format of the--add-dataoption isSRC;DEST. If you want to copy multiple directories, you can use multiple--add-dataoptions.--icon="assets/editor.png"option specifies the icon for the main window.--name editoroption assigns a name to the program i.e.,editor. If you ignore this option, PyInstaller will use the Python file as the program’s name e.g.,main.--noconfirmoption will remove the existingbuildanddistdirectories without confirmation if you execute the command again.
Summary #
- Use Pyinstaller to convert a PyQt program to an executable file.