Python – Convert .py to .exe

Convert Python file to Exe File

To convert a .py (Python) file to .exe (executable), you can use pyinstaller package and run the pyinstaller command in command line.

In this tutorial, we will take a simple python file that prints “Hello World!” to console and convert this python file to executable file.

Step by Step process to convert .py to .exe

Step 1: Install pyinstaller

Open Command Prompt or Terminal, and run the following pip command to install pyinstall.

pip install pyinstaller.

Step 2: Go to .py location

Open Command Prompt or Terminal and navigate to the location of .py file, you would like to convert to .exe.

Navigate to the location of Python file

There is our hello_world.py file. We will convert this python file to exe file.

Step 3: Run pyinstaller command

From the location of .py file, run the following command, to build and create .exe file from python file.

pyinstaller --onefile -w hello_world.py

You will get following information in Command Prompt.

Python .py to .exe

Next to the Python file, build and distribution directories will be created.

Python .py to .exe - Build and Distribution Files

Step 4: .exe File

Go inside dist directory and you will find .exe file.

Python .py to .exe - Output Executable File

Summary

In this tutorial of Python Examples, we learned how to build a .exe from .py.

Code copied to clipboard successfully 👍