Convert python file to .exe

Not all systems will have python installed to run your code. That's when you have to convert your python (.py) file to an (.exe) executable file.



To convert, we will use the pyinstaller module.

Installation

pip install pyinstaller

Creating .exe

Open a Terminal or PowerShell window and change directory to the location of the python file you want to convert.
Here we will convert Snake.py to .exe

Type in the following command in your Terminal/PowerShell.

pyinstaller --onefile Snake.py


The converted executable file will be present in the dist folder.


To add an icon to the .exe file, use the -i option

pyinstaller --onefile -i logo-ico.ico Snake.py
 


Make sure that the icon and the python files are in the same directory or provide the complete path of the icon.


If you would like to contribute to Hackzism you can also write an article and mail to  hackzism.hack@gmail.com
Your article will be published on our home page.

Comments

Popular Posts