Your Logo

Creating a Standalone Python Application

This guide will show you how to convert an existing Python application into a standalone executable file using PyInstaller.

Packaging a Python Application into a Single Executable (.exe) with PyInstaller

This guide explains how to package your Python application into a standalone Windows executable file (.exe) using the PyInstaller library. This allows you to distribute your Python app without requiring users to have Python installed.


Prerequisites


1. Activate Your Virtual Environment

If not already activated, activate your virtual environment where your project dependencies (including PyInstaller) will be installed.


2. Install PyInstaller

Install the PyInstaller package inside your virtual environment:

pip install pyinstaller

3. Package Your Python Script

Navigate to your project directory containing your main script (app.py).

Run PyInstaller with the --onefile option to create a single executable file:

pyinstaller --onefile app.py

NOTES:
- You can replace pyinstaller with python -m PyInstaller or python3 -m PyInstaller if pyinstaller command is not found. - The --onefile flag bundles everything into one executable file instead of a folder with dependencies.


4. Locate the Executable File

After PyInstaller finishes, it creates several new folders and files.

Example path:

my_python_project/
├─ dist/
│  └─ app.exe
├─ build/
├─ app.py
├─ app.spec
└─ ...

5. Test the Executable


6. Optional PyInstaller Flags

Here are some useful PyInstaller command options you might consider:

Example combining options:

pyinstaller --onefile --noconsole --name MyApp --icon myicon.ico my_script.py

7. Cleaning Up


Summary

Step Command Example
Activate virtualenv .venv\Scripts\activate.bat (Windows CMD)
Install PyInstaller pip install pyinstaller
Create single exe pyinstaller --onefile app.py
Run executable dist\app.exe

You now have a standalone Windows executable of your Python application ready for distribution!


Troubleshooting Tips