Developer Snippet Diary

PYthon code to exe

Converting a Python script into an installer allows you to distribute your program as a standalone executable file that can run on computers without requiring Python to be installed. One of the most popular tools for this is PyInstaller, which bundles your Python code, dependencies, and the Python interpreter into a single executable. This tutorial will guide you through the process of creating an installer using PyInstaller.

 

1. install py installer

pip install pyinstaller

2. use it

pyinstaller --onefile script.py

After PyInstaller finishes, the executable will be in the dist folder within your working directory. For example, dist/script.exe (on Windows) or dist/script (on macOS/Linux).

Full example:

pyinstaller --onefile --noconsole --upx-dir "D:\Documents\program\python\typing tool" --icon=icon.ico --hidden-import=keyboard --hidden-import=pyautogui --exclude-module=numpy --exclude-module=cv2 typing_tool.py

 

UPX is tool to reduce the size of exe: download from https://upx.github.io/ and paste exe in current directoy 

Posted by: R GONDAL
Email: rizikmw@gmail.com