Make executable for distribution (PyInstaller)¶
You can create a executable file (.exe) to distribute GUI programs created using Python and PyQt5.
The executable allows you to run programs even if you don’t have Python installed.
You can easily create executables using a package called ‘PyInstaller’. (PyInstaller official website )
Install PyInstaller¶
First, install the PyInstaller package using the following command from the command prompt.
pip install pyinstaller
Make executable¶
Navigate to the folder where the Python file(.py) is located, and then type this command to create a executable in that folder.
pyinstaller grid_layout.py
If you move to dist from the foler and go in once more,
can find the executable as shown in the figure below.
If you double click to run, the console window will be print as shown in the figure below.
Prevent console window from being print¶
To prevent the console window from being print, add ‘-w’ or ‘–windowed’ to the command as shown below.
pyinstaller -w grid_layout.py
Create one executable¶
If you add ‘-F’ or ‘–onefile’ to the command, only one executable is created as shown below.
pyinstaller -w -F grid_layout.py