π Quick Overview
- Goal: Turn a .py file into a standalone .exe file.
- Tool: PyInstaller (Free & Open Source).
- Time to Complete: 5 Minutes.
- Key Command:
pyinstaller --onefile --noconsole script.py
Youβve just built a stunning Python Dashboard or an automation script. You send it to your friend, and they ask: “How do I run this? Do I need to install Python?”
If you want to share your work with non-developers, you cannot ask them to use the terminal. You need to give them a double-clickable .exe file.
In this guide, we will use PyInstaller to package your Python code into a single executable file that runs on any Windows machineβeven if it doesn’t have Python installed.
Step 1: Install PyInstaller
Open your terminal (Command Prompt or PowerShell) and run:
pip install pyinstallerNote: If you are using a Virtual Environment (which you should be!), make sure it is activated first.
Step 2: The Basic Conversion
Navigate to the folder containing your script (let’s say it’s called dashboard.py). To create a basic executable, run:
pyinstaller dashboard.pyThis will create a dist/ folder containing your .exe. However, by default, PyInstaller creates a folder with many dependencies. We usually want just one single file.
Step 3: Creating a “One-File” Bundle
To bundle everything into a single standalone file, use the --onefile flag:
pyinstaller --onefile dashboard.pyCheck your dist/ folder. You will now see a single dashboard.exe file. You can move this file anywhere, and it will run!
Step 4: Hiding the Console (Critical for GUIs)
If you are packaging a GUI app (like the CustomTkinter Dashboard we built previously), you don’t want a black command prompt window popping up behind your app.
To hide it, use the --noconsole (or -w) flag:
pyinstaller --onefile --noconsole dashboard.pyThis is the gold standard command for Python GUIs.
Sometimes, Windows Defender or other antivirus software might flag unassigned .exe files created by PyInstaller as “suspicious.” This is normal for unsigned software. If this happens, you may need to add an exclusion to your antivirus folder.
Step 5: Handling Images and Assets (The “Pro” Tip)
If your script loads images (like a logo), PyInstaller won’t include them automatically. You have two options:
- The Lazy Way: Copy the images folder into the same directory as your new .exe file.
- The Pro Way: Use the
--add-dataflag to bundle them inside the .exe.
pyinstaller --onefile --noconsole --add-data "logo.png;." dashboard.py(Note: On Mac/Linux, replace the semicolon ; with a colon :).
Conclusion
Congratulations! You have just moved from “Scripting” to “Software Distribution.”
Now that you can share your apps, what will you build next? Check out our guide on GUI Design Rules to make sure your new .exe looks professional.






