In this article we are going to learn How to Convert Python PY File to EXE File, also we
will learn how you can create installer for your application. for converting PY to EXE we
are going to use pyinstaller library, and for making installer we want to use inno setup
application. pyinstaller is a library that you can use for you can use for converting of your
PY file to EXE file.
- Python Top 5 Game Libraries
- Python GUI Development Libraries
- Web Development Libraries in Python
- How to Download Youtube Videos in Python
- Working with Python Pyglet Library
- Python Speech Recognition For Beginners
Installation
First of all you need to install pyinstaller, you can use pip for the installation.
1 |
pip install pyinstaller |
OK in this example we are going to create a GUI application using PyQt5,
so PyQt5 is a binding for Qt5 C++ a GUI framework for C++ programming language,
PyQt5 is used to write all kinds of GUI applications, from accounting applications, to
visualization tools used by scientists and engineers. it is possible to write PyQt5 applications
that are just tens of lines long, and medium-size projects of 1000 to 10000 lines are very
common. if you are not using PyQt5 you can use another Python GUI Libraries like
TKinter, Kivy or wxPython.
basically this is a simple code for creating of a basic window in pyqt5, we want to first
convert this python PY file to EXE and after that we make an installer for our application
using InnoSetup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel import sys from PyQt5.QtGui import QIcon, QFont class WindowExample(QWidget): def __init__(self): super().__init__() self.setGeometry(200,200, 400,300) self.setWindowTitle("Codeloop.org") self.setWindowIcon(QIcon('python.ico')) self.setStyleSheet('background-color:red') vbox = QVBoxLayout() label = QLabel("Welcome to GeeksCoders.com") label.setFont(QFont("Sanserif", 14)) label.setStyleSheet('color:white') vbox.addWidget(label) self.setLayout(vbox) app = QApplication(sys.argv) window = WindowExample() window.show() sys.exit(app.exec_()) |
Now let’s convert this PY file to EXE, first of all you need to copy this file in your
Scripts folder.

and after that run this command, make sure that you have also copied an icon
in the Scripts folder.
1 |
pyinstaller --onefile --windowed --icon=python.ico window.py |
What to generate Option
-D, --onedir | Create a one-folder bundle containing an executable (default) |
-F, --onefile | Create a one-file bundled executable. |
--specpath DIR | Folder to store the generated spec file (default: current directory) |
-n NAME, --name NAME | |
Name to assign to the bundled app and spec file (default: first script’s basename) |
Windows and Mac OS X specific options
-c, --console, --nowindowed | |
Open a console window for standard i/o (default). On Windows this option will have no effect if the first script is a ‘.pyw’ file. | |
-w, --windowed, --noconsole | |
Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. On Windows this option will be set if the first script is a ‘.pyw’ file. This option is ignored in *NIX systems. | |
-i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon <FILE.ico or FILE.exe,ID or FILE.icns> | |
FILE.ico: apply that icon to a Windows executable. FILE.exe,ID, extract the icon with ID from an exe. FILE.icns: apply the icon to the .app bundle on Mac OS X |
After that you will have two directory in your Scripts folder.

Also you can find the exe file in the dist folder.

How to Convert our EXE to Setup Installer
OK sometimes you need to create an installer for your application, for example you
have created your application and you want to sell that application or you want to give
that for your friend, for this you want to create an installer that they can install your
application in their computers, for creating of installer we need to use InnoSetup.
Now make two folders and copy your two directories of dist and build, paste
that in your created second folder. also copy your icon in that folder like this.

Now open your InnoSetup, from File choose New and after that you need to
add your application information that you want to make setup installer.

After that click on next, there will be another page of Application Folder, you don’t need
to bring changes in their, just click on next.
Now we have Application Files page, in here in the Application main executable you need to
Browse your exe file from the folder that you have already copied. after that click on the
Add Folder and you need to add your main folder that includes the dist and build folders.

Than click on next you will see Application Shortcut page, you don’t need to bring
any changes in their, just click on next.

after that there will be Application Documentation, like you can add license
and before installation instructions for the application, iam not going to give any
documentation for the application so just click on next if you don’t want.

Don’t bring any change in the setup install mode page click on next.

After that choose your language and click on next, now you need to give the
compiler output folder also add your icon in here.

Click on next and finish, now you are done and you have a setup for your application,
you can install that on your computer and you can give the installer for your friends,
they install the application and use from that.