Convert a Python Script into an .exe File

 

 

 

Sometimes it's useful to run a Python script simply by double-clicking a desktop icon.

 

 

 

Installing pyinstaller

pip install pyinstaller==5.13.2

 

Example script

import time

print("Hello World!")

time.sleep(5)


 

Creating the .exe 
Run the following command in the same directory as script.py and logo.ico (the logo is optional).

pyinstaller --onefile --icon=logo.ico script.py


--onefile creates a single executable
--icon sets the application icon

 


The .exe file is inside the dist folder.
You can move the .exe and delete everything else.


pyinstaller==5.13.2