In this article we are going to talk about Python to EXE Converter, also we will learn how you can create installer for your application. for converting Python script 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 building Python to EXE Converter.
Learn More on PyQt5
- How to Deploy PyQt5 Applications
- How to Integrate PyQt5 with OpenCV
- How to Use Stylesheets in PyQt5
- Learn PyQt5 Event Handling with Signals and Slots
- PyQt5 Tutorial: Creating Menus and Toolbars
- How to Open & Save Files in Python PyQt5
- PyQt5 Designer Tutorial: Complete Guide to Qt Designer
- PyQt5 vs Tkinter: Which GUI Library is Right for You
- How to Build Web Applications in PyQt5
- How to Integrate Python Flask with PyQt5
First of all you need to install pyinstaller, you can use pip for the installation.
pip install pyinstaller
Python to EXE Converter
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 script to EXE and after that we make an installer for our application using InnoSetup.
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PyQt5.QtGui import QIcon, QFont
vbox = QVBoxLayout()
label = QLabel("Welcome to GeeksCoders.com")
app = QApplication(sys.argv)
window = WindowExample()
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.
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.