How to Convert Python to EXE

PyInstaller is the most popular tool for converting Python scripts into standalone executables. It bundles your Python code and all dependencies into a single .exe file that runs on Windows without requiring Python to be installed.

1Install PyInstaller

Open a terminal and run: pip install pyinstaller

2Navigate to Your Script

Open a command prompt and navigate to the directory containing your .py file: cd C:\path\to\your\project

3Run PyInstaller

Execute: pyinstaller --onefile your_script.py The --onefile flag bundles everything into a single .exe. Without it, PyInstaller creates a folder with multiple files.

4Find Your EXE

The compiled executable will be in the dist/ folder: dist/your_script.exe. You can distribute this file to anyone with a compatible Windows system.

Frequently Asked Questions

Why is my EXE file so large?
PyInstaller bundles the entire Python runtime and all imported packages. Use --exclude-module to remove unused modules, or consider using a virtual environment with only needed packages.
Can I create a Mac app from Python?
Yes. PyInstaller works on macOS too. Run the same command on a Mac to create a macOS executable. You cannot cross-compile (create a Mac app on Windows or vice versa).