DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on

Convert Python Script To Exe File Using Pyinstaller

“How to convert Python Script to .exe file?” – Every python developer asks this question when they want to share their developed python application to the outer world. In this blog, we will take a detailed view on how to convert our python program to an executable file using a python module i.e pyinstaller.

Why Can’t Share .Py File?

While developing in python, we install many packages and use them in our program. Those installed packages are present in our development environment.

When we share our python file to another machine, for that python program to run on that machine the same packages should be present.

One easy way to install all the packages is to use the requirements.txt file which has all the list of installed packages needed for that python program to run.

Fill The Requirements.Txt File

This command should be executed on the development environment of the python developer.

Fill requirements.txt file

$ pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

Install Packages From Requirements.Txt File

This command should be executed on the machine where the python packages are to be installed to run the shared .py file.

Install packages from requirements.txt

$ pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

But what if, the developer doesn’t want to share the requirenments.txt file and still want to run that developed application on another machine.

This problem can be solved when we convert the python script file (.py) to an executable file (.exe).

The obtained executable file can run on the windows platform and it contains all the packages needed to run the python program.

What Is Pyinstaller?

Pyinstaller is a python package that bundles a Python application and all its modules/dependencies into a single package.

This makes tasks easier for the user, as the user can run the bundled app without installing a Python interpreter or any module on the machine.

Pyinstaller also supports many python libraries like NumPy, PyQt, Django, wxPython, and others.

Learn more about how to convert python script to exe file.

Top comments (2)

Collapse
 
whjeon profile image
WooHyung Jeon

Good! I also want to know how the patch(application update) works! Can you show me a intuitive explanation?

Collapse
 
divshekhar profile image
Divyanshu Shekhar

I'll have to look at it!