Creating a Standalone Python Application

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

Step 1: Install PyInstaller

First, you need to install PyInstaller. You can install it using pip:

pip install pyinstaller

Step 2: Navigate to Your Script's Directory

Then, navigate to the directory where your Python script is located.

Step 3: Convert Your Script into an Executable

Run the following command:

pyinstaller --onefile your_script.py

Replace "your_script.py" with the name of your Python script.

Step 4: Find Your Executable

PyInstaller will create a "dist" directory in the same directory as your script. Inside this "dist" directory, you will find your standalone executable file.

Note:

If your script depends on other files (like images, data files, etc.), you need to specify them so PyInstaller can include them in the executable. You can use the --add-data option for this:

pyinstaller --onefile --add-data 'path/to/data/file:data' your_script.py

In the --add-data option, "path/to/data/file" is the path to the data file you want to include, and "data" is the directory where the data file will be placed in the executable. If you have multiple data files, you can specify them by separating them with a semicolon.

Important:

When you create an executable file from a Python script, the executable will only run on the operating system you created it on. That means if you create the executable on Windows, it will only run on Windows. If you need to run it on a different operating system, you need to create the executable on that system.