How to Convert Python Scripts to .EXE Files: The Complete PyInstaller Guide (2026) πŸ“¦

Convert Python Scripts to EXE

πŸš€ 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 pyinstaller

Note: 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.py

This 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.py

Check 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.py

This is the gold standard command for Python GUIs.


⚠️ Important Warning: Antivirus False Positives
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:

  1. The Lazy Way: Copy the images folder into the same directory as your new .exe file.
  2. The Pro Way: Use the --add-data flag 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top