Python File to Executable File

Mausam Singh
2 min readJan 4, 2021

--

It is an executable file format and it contains a program and has the ability to run as a program in computer. It does not require any import statements to execute. Just Double Click is enough to run the exe file.

Hope, python is already installed in your system and now, we will use the pyinstaller. So, Let’s get started.

Pyinstaller is a tool for Python that lets you bundle up an entire Python application into a one-file executable bundle that you can easily share.

Convert a .py to .exe in windows. Converting python files to executable’s is fairly simple and we do this using pyinstaller. This method will work for one file or for multiple files that require dependencies such as images or other modules.

pip install pyinstaller

To Check, if the pyinstaller is installed

pyinstaller 

Pyinstaller version

pyinstaller --version

Let’s get Started.

  1. Create a python file. Open Command prompt and run python file to check whether the code runs successfully without any error.
  2. Create an exe file.
  • Go to the folder where the .py file is saved. Open the command prompt in that folder.
pyinstaller file_name.py

pyinstall command might create lot of files inside dist folder. If you want to have a single application file. To create an single executable file

pyinstaller --onefile file_name.py

To create an single executable file with an icon

pyinstaller -F -w -i "icon_file.ico" file_name.py

Example:-

pyinstaller -F -w -i "kingbondl.ico" flappy.py

Conclusion:

PyInstaller provides multiple options to create a simple to the complex executable for a Python script.

Your application will be created inside the build folder.

--

--

Mausam Singh
Mausam Singh

Written by Mausam Singh

Aspiring Product Manager | Android Developer | Ex-SDE at Meesho | I believe in writing for self reflection and reading for self development.

No responses yet