How to create a standalone EXE setup for python application projects

How to create a standalone EXE setup for python application projects: I am creating a Python song lyrics app with a Qt GUI for windows. Some end-users use Linux, but most of them are users of Windows who are unfamiliar with Python or an interface with commands. It’s hard to spread Python apps to non-programmers end-users.

So, in this tutorial, you will learn How to create a standalone EXE setup for python based project applications using Inno setup(a most popular and powerful setup maker application for windows)

How to create a standalone EXE setup for python application projects: I have Qt project in which I have used python and its different modules, but the problem is when I made a setup(EXE) for windows using Inno, then the application needs python dependency in the windows system. That means if a user had not installed python on the machine, the application would not run. So In order to run that application user must installed python and set environment variable path of python in the system. but at the user ends it is not expected that the user is aware of these things. A user only needs the application to be running in their system. It’s a programmer job to make application all dependency free Applications.

Now solution in one line is WinPython and Inno Setup.

WinPython is a portable free Windows distribution for Python, meaning it is totally isolated from the remainder of the scheme. WinPython can be mounted in a folder that is fully functional and can be relocated anywhere, even on a USB stick. WinPython has bundled with many Python packages already, but you can download zero version of Winpython because it is smaller in size(Almost 25MB).

Inno Setup is a free Windows installer software. Building an installer involves writing a plain text script containing directions on what and where to install. It has many characteristics, including shortcuts for desktop and begins menu, post-install scripts, and so on. A wizard makes it easy and quick to get started.

Must see: how to deploy Qt projects:

Must see: how to add icon in your QT project application

Steps to create a standalone EXE setup:

1- Download Winpython (download zero-version it’s small and lightweight) and install it in your machine. now go to the installation directory and copy the entire directory. (this is your python distribution) into your project directory.

In my case the project directory is :

How to create a standalone EXE setup for python application projects_project dir

Winpython directory is :

How to create a standalone EXE setup for python application projects winpython dir

2- Inside your Winpython directory you have WinPython Command Prompt, that will help you to install python external modules. In my case, I have installed some module explicitly. for eg bs4, requests, lxml, etc

To install python additional modules you need to run WinPython Command Prompt and install it using PIP command.

In my case, I have installed bs4, requests. In your case, it could be different.

  • pip install bs4
  • pip install requests
pip install How to create a standalone EXE setup for python application projects
how to install modules in python

Note: You must install modules which are needed for your project. Otherwise, it would not work for you. and please do not install libraries which are not useful, because your setup size will gonna increase.

3- How to create a standalone EXE setup for python application projects: Now install Inno setup in your machine and run the program and create an Inno script. If you don’t know how to create an Inno script then watch this video. (very useful)

4- Now in inno script make some changes. Your script should look like this.

view of inno script

After changes it should look like this:

inno script How to create a standalone EXE setup for python application projects

Add the code line in [files] section(this is to add the python directory into your project)

[Files]

Source: "C:\Users\risha\Documents\lyricpad-master\build-lyricspad-Desktop_Qt_5_12_3_MinGW_32_bit-Release\release\WPy64-3720*"; DestDir: "{app}\WPy64-3720"; Flags: ignoreversion recursesubdirs createallsubdirs

Note: In most cases, the directory name should be WPy64-3720. if not then, Replace ‘WPy64-3720’ to your [directory name].

Add this code in registry section. if you don’t have registry section then create one. ( This is for setting up python in Environment variable )

[Registry]

Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "Path"; ValueData: "C:\Program Files (x86)\LyricPad\WPy64-3720\python-3.7.2.amd64"; Flags: preservestringtype

Note: Replace valueData path to your directory path

How to create a standalone EXE setup for python application projects changes made in inno script

Note: Replace valueData path to your directory path

5- Now run the script and you will see Inside your project directory, Winpython directory is there, also Environment variable python path will be set.

Conclusion:

How to create a standalone EXE setup for python application projects: This solution works for me and is adaptive for me. But I don’t think this is the only method to do. if you have another method then you are free to do.

That’s all.. if you have a problem/doubt in anywhere, then feel free to ask in the comments section.