This guide will show you how to convert an existing Python application into a standalone executable file using 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.
virtual environment activated..exe).
If not already activated, activate your virtual environment where your project dependencies (including PyInstaller) will be installed.
.venv folder on Windows Command Prompt:
.venv\Scripts\activate.bat
.venv\Scripts\Activate.ps1
Install the PyInstaller package inside your virtual environment:
pip install pyinstaller
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 replacepyinstallerwithpython -m PyInstallerorpython3 -m PyInstallerifpyinstallercommand is not found. - The--onefileflag bundles everything into one executable file instead of a folder with dependencies.
After PyInstaller finishes, it creates several new folders and files.
.exe file will be located in the dist folder inside your
project
directory.Example path:
my_python_project/
├─ dist/
│ └─ app.exe
├─ build/
├─ app.py
├─ app.spec
└─ ...
dist\app.exe or running it from the command line:
dist\app.exe
Here are some useful PyInstaller command options you might consider:
--onefile: Bundle everything into a single executable file (instead of a folder).--windowed or --noconsole: Prevent a console window from appearing. --windowed is typically used for GUI apps on Windows and macOS. --noconsole is an alias on Windows for the same effect, hiding the console.--icon=path/to/icon.ico: Include a custom icon for your executable.--name=YourAppName: Specify a custom name for the executable file.Example combining options:
pyinstaller --onefile --noconsole --name MyApp --icon myicon.ico my_script.py
build folder and .spec file manually if you
like.
| 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!
.exe works standalone.