“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.
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.
This command should be executed on the development environment of the python developer.
Fill requirements.txt file
$ pip freeze > requirements.txt
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
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.
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.