How to Create Exe File for Python Program using Pyinstaller

What if you have a single exe file that can be run without a python interpreter? If you have these questions, then you are at the right place. Today, we will create an exe file for a python program using Pyinstaller.

How to Run a Python Script from PHP

Note: Exe files can be created on any platform but can only be run in windows based system.

Step 1: Install and Add Python to Windows Path

You might have already installed python in your system. But for those who don’t, you can download it from the official website.

While installing, make sure to click on the checkbox with the message “Add python* to PATH”.

Python Installer
Python Installer

This will allow us to access python and PIP directly from the command prompt.

Step 2: Install the Pyinstaller Package

Next, you have to open a command prompt using the search bar and type CMD or the WIN+R shortcut key to open the Run application and type CMD.

Note: For the Linux family, you can have this package in your system to create an exe file. But that file can only be run in Windows.

Once your command prompt is ready, you can copy or write the below command to install Pyinstaller in your system.

pip install pyinstaller

Step 3: Create Python Program

Now only one main ingredient is left in your system before creating an exe file—a python program, which we will use in this experiment.

I already created a basic python program, not too fancy. Its role is to display “Pyinstaller Guide” in Tkinter Window. In your case, it can be a complex program written in NumPy, PyQT, wxPython, etc.

from tkinter import *

app = Tk()

app.title("TREND OCEANS")
l = Label(app, text="Pyinstaller Guide", font=("Arial Bold", 20))


For instance, you can use the above code and save it with the “.py” extension. Personal suggestion, while saving your file, make sure the directory is empty. So, when we create an exe file, it can be easily spotted.

Step 4: Create the Exe File using Pyinstaller

I think your command prompt is still open from step 2. I recommend closing it, or if you are a tech geek, you can directly navigate to the location where you have saved your python program from step 3.

Otherwise, navigate to file location from the file explorer click and type cmd in the address bar like shown below.

File explorer
File explorer

Finally, we can execute the pyinstaller command to generate an exe file from our python program. Below is the syntax of the command we will use.


pyinstaller --onefile []

If you use a custom program, replace the with [yourfilename].py. In my case, it’s

pyinstaller --onefile
Create Exe File for Python Program using Pyinstaller
Create Exe File for Python Program using Pyinstaller

After you execute the above command, it will create a few files & folders in the current directory. You have to enter in the dist directory.

Navigating to dist folder
Navigating to dist folder

Once you enter the directory, only a single file will be there with the same name of your file but with a “.exe” extension.


You can quickly run this application from the context menu or double-clicking on the exe file.

Python Program with Console
Python Program with Console

While your application is running behind the scene, you will also spot your console is also running. To hide that console whenever you run your application pass –noconsole option while generating exe file.

pyinstaller --noconsole --onefile
Python Program
Python Program without Console

If you have any issues while creating exe files from the python program. Let us know in the comment section so that we can guide you.

0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Iancu Ioan
2 years ago

How can I create a shortcut to Desktop from inside the python script so after I made the .exe and send by email to a user shortcut appear on Desktop. Thanks.

Iancu Ioan
2 years ago

Thanks Jake Redfield, your answer was very helpfull. Yes, the shortcut is created after the first run of the .exe. Is there any posibility to create the shortcut when users download compresed(archived) .exe from email or from a link? Thank you very much.