Make executable for distribution (PyInstaller)

_images/7_1_1_pytoexe.png

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
_images/7_1_2_install.png

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
_images/7_1_3_make_exe.png

If you move to dist from the foler and go in once more,

_images/7_1_4_find_exe.png

can find the executable as shown in the figure below.

_images/7_1_5_find_exe.png

If you double click to run, the console window will be print as shown in the figure below.

_images/7_1_6_exe.png

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
_images/7_1_7_exe.png

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
_images/7_1_8_exe.png

Prev