Lesson 21: Creating Executable Applications

How to turn your Python scripts into standalone executables

Why Create Executables?

Packaging your Python program as an executable allows users to run it without installing Python or dependencies. This is useful for distributing tools to non‑technical users or deploying applications on systems where Python is not available.

Using PyInstaller

PyInstaller is the most common tool for creating executables.

Installing PyInstaller

pip install pyinstaller

Creating a Simple Executable

pyinstaller myscript.py

This generates a dist/ folder containing the executable.

One‑File Executables

Bundle everything into a single file:

pyinstaller --onefile myscript.py

Adding an Icon

pyinstaller --onefile --icon=app.ico myscript.py

Handling External Files

If your program uses images, data files, or templates, you must include them manually:

pyinstaller --onefile --add-data "data.json;." myscript.py

Spec Files

PyInstaller generates a .spec file that you can edit to customize the build process. This is useful for complex applications with multiple resources.

Testing the Executable

Alternatives to PyInstaller

Best Practices

Next Steps

Now that you can create executables, you're ready to explore how to deploy Python applications in Lesson 22: Deploying Python Applications.

← Back to Lesson Index