How to Create an EXE Executable on Windows from Your Python Code

How to Create an EXE Executable on Windows from Your Python Code

A guide to creating an EXE file on Windows from Python code.

Are you a developer who is looking to share his/her work with friends or community members who are not from a tech or programming background, or to friends who want to execute a specific task (which your code can solve) without installing or coding any IDE, in that case sharing an EXE file on Windows is your best solution available.

Rapid Application Building and Deployment

EXE is the name of a file extension denoting executable files on Microsoft Windows.

Windows Executable

Let's see an end-to-end one-stop solution for building an EXE file from your Python code.

One Step conversion of Python to EXE

Converting Python to EXE

So let's get started, to convert Python to EXE we will be using this open-source Python package which is known as auto-py-to-exe.

Auto Py to EXE UI

To install auto-py-to-exe, the basic requirement is that we must have Python and pip installed on our developer workstation.

To do the installation, we will have to execute the command pip install auto-py-to-exe on our command-line shell.

pip install auto-py-to-exe

Once we have installed it, we can directly run auto-py-to-exe from the command line itself and see the output.

Running Auto-py-to-exe

We will be using simple code to make GUI in Python and convert it to EXE soon. Here is the code for reference.

Once you open the auto-py-to-exe package, just add your Python script path as shown in the below screenshot.

Once done with specifying the script location, select the output location as shown in the below screenshot, followed by clicking upon the blue coloured label button.

As soon as you click “CONVERT .PY TO EXE “, this next window will look like this:

EXE Build Output

Internal Procedure for Building EXE

Once you open the output file, you will have your running GUI EXE file:

Click on the GUI_exe

The output will look something like this:

Output of EXE

Happy Coding!

Note: Make sure that you have installed all the python packages and libraries used in the python script via pip because auto-py-to-exe will combine all those libraries available in the current machine and later build an EXE file. If you do not follow this, the EXE file when given to another machine will throw an error of no module found (with the name of the relevant library).

For any further queries or anything related to Automation via Python or DevOps, you can DM me on Linkedin or Instagram id=acanubhav94.

Special credits to my team interns: Kishan and Pratik.

More content at plainenglish.io. Sign up for our free weekly newsletter. Get exclusive access to writing opportunities and advice in our community Discord.