search
top

Converting a Python Script to Windows Executable

Normally, when we want to install a Microsoft software, we go to the source be the Microsoft Store or any website offering the software. We then download an installer which normally is an (.exe) file. Ones installing it generates many files and folders which are stored in the C:\Program Files.

 
 

Prerequisites

  • Little knowledge of python
  • Python installed in your Windows OS

Have you ever wondered the complexity it takes to create a windows software? Well, I have. Some are complex, some are not as we will see. We will make a simple Python application, then deploy it into a Microsoft Software.
So, let’s buckle up and start the 3-minute journey or so… ☺

 

Installing the Package

First we will install auto-py-to-exe Library. This will help us converting our python script to a Microsoft software package.

pip install auto-py-to-exe

 

Python Script

Copy paste the script below and save it in your preferred location.

from tkinter import *
from tkinter.ttk import *
# creating tkinter window
root = Tk()
def answer():
showinfo(“Answer”, “You got good taste”)
Label(root, text = ‘Do you like Pizza’,font =(‘Verdana’, 15), justify=CENTER).grid()
Button(root, text = ‘Yes’,command=answer).grid(row=1,column=0)
Button(root, text = ‘No’).grid(row=1,column=1)
mainloop()

The Output of this Simple Script is shown below

Example Screen1

 

Deploying the Python script to a Windows app

Since you have installed the auto-py-to-exe library successfully, go to the cmd and type auto-py-to-exe

Example Screen2

This command will prompt

Example Screen3

 

  • In the Script Location, specify the path of your python script. As you can see, pizza python script Is saved in the Desktop.
  • In Onefile, there are two options: One Directory and One File. One file, as it says, enable the script to be packaged as a single exe file. In One Directory the application comes with the full building packages of a Microsoft software program. An example of this is a folder of a program in your Program Files the (C:) Drive.
  • The Console Window section gives you an option on whether you want to display a console when running your new program or not.
  • Luckily enough, you can also design and choose the icon of your liking.

 
Lastly you click the CONVERT .PY TO .EXE button, after a few minutes, your application is ready in the output folder that the application will direct you to. Wonderful, Right?
You can explore more about auto-py-to-exe here

 

Summary

We have seen how to install auto-py-to-exe for conversion of a python project to a windows application. You can create a fully-fledged python GUI application using Tkinter or PyQt libraries and deploy your applications the same way. Aint that cool?

 
If you’re reading this, it means you’ve followed the steps and read the whole blog. It also may happen that you had a lot, if not few things to thank about the past year 2019. I take this opportunity in this forum here to thank Techno Dossier and its administrator for giving me this platform to share my knowledge, which is a fun thing for me. Adios! Hasta La Vista!!!

One Response to “Converting a Python Script to Windows Executable”

  1. Edwin says:

    wonderful. Seems so easy!

Leave a Reply

Your email address will not be published.

top