A simple script that converts any Python (.py) file into a standalone Windows .exe, using PyInstaller under the hood.
- Auto-installs PyInstaller if it's not already installed
- Lists all
.pyfiles in the current folder - Asks you which file to convert
- Builds a single-file
.exe(no extra files needed to run it) - Credit: MEDU 🛠️
- Python 3.7+ installed
- Windows (to actually run the resulting
.exe; you can build it on other OSes too, but the.exeonly runs on Windows) - Internet connection (only needed the first time, to install PyInstaller)
- Put
py2exe_by_medu.pyin the same folder as the.pyfile you want to convert. - Open a terminal / command prompt in that folder.
- Run:
python py2exe_by_medu.py - The script will:
- Check/install PyInstaller
- Show you all
.pyfiles in the folder - Ask you to type the filename you want to convert (e.g.
myscript.pyor justmyscript)
- Wait for the build to finish.
- Your
.exewill be inside the newdist/folder, e.g.:dist/myscript.exe
After running, PyInstaller creates some extra files/folders — this is normal:
dist/→ contains your final.exe(this is the only one you need)build/→ temporary build files (safe to delete)*.spec→ PyInstaller config file (safe to delete, or keep if you want to rebuild easily)
"PyInstaller not found" keeps appearing
Make sure pip works properly. Try manually:
pip install pyinstaller
The .exe doesn't run / closes instantly
Run it from a terminal (cmd) instead of double-clicking, so you can see any error messages:
dist\myscript.exe
Antivirus flags the .exe This is a common false positive with PyInstaller-built executables. It's not actually a virus — you may need to whitelist it.
My script uses extra files (images, data, etc.)
This script does a simple --onefile build. If your project needs extra files bundled in, you'll need a custom PyInstaller --add-data setup.
Script & idea: MEDU Built using PyInstaller.