Based on: https://youtu.be/tmc67kpzq88
This guide explains how to convert a Streamlit app into a standalone
Windows EXE using cx_Freeze.\
It also includes notes for OpenAI, Google Gemini, and pyttsx3 (TTS) support.
To build a standalone executable:
- Update your
app.pyandsetup.py - Add hidden/implicit imports (Streamlit, OpenAI, Gemini, pyttsx3)
- Run
cxFreeze.bat - Copy
app.pyandsetup.pyinto the newToRunfolder - Run your EXE
- (Optional) Change the EXE icon
π 1. Add Required Imports (Hidden Dependencies)
Some libraries used by Streamlit, OpenAI, Gemini, and pyttsx3 are not automatically detected by cx_Freeze.
Add these imports inside your setup.py to force cx_Freeze to
include them:
# --- Streamlit hidden/implicit imports ---
import streamlit.runtime.scriptrunner.magic_funcs # Force cx_Freeze to bundle this
import streamlit.web.cli as stcli # Ensure Streamlit CLI is included
# --- OpenAI ---
import openai
import sys
import os
import base64
from pathlib import Path
# --- pyttsx3 (TTS / pysttx) ---
import pyttsx3
import pyttsx3.drivers.sapi5
import tempfile
import comtypes.stream
# --- Google Gemini ---
from google import genai
from google.genai import typesIf you are using new python libraries this may be a bit of trial and error when the EXE fails just add them one by one until they work!
After your setup.py is ready, run:
cxFreeze.bat
This process may take some time depending on your dependencies.
After the build completes, you should see a folder named:
ToRun/
Inside this folder:
- Copy your
app.py - Copy your
setup.py - Run the generated
.exeinside the folder
Streamlit often requires original Python files to remain accessible.
You can update the generated EXE's icon using:
Requirements for Icon Changer
pip install pillow pywin32
- WIN_ChangeIconForEXE
Replace the default cx_Freeze icon with a png!
- If your EXE crashes or fails to run, you likely need to add more
hidden imports to
setup.py. - Ensure any API keys (OpenAI, Gemini) are accessible in environment variables or config files.
- pyttsx3 (
sapi5) and Streamlit can introduce extra dependencies---test thoroughly. - Virus scanners some times don't like the buld process or the exe they may attempt to quarantine it π¦