How to Convert a Streamlit App to an .EXE Executable
Table of Contents
Introduction
In this tutorial, you'll learn how to convert a Streamlit app into an executable (.EXE) file using a streamlined process involving WebAssembly and Electron. This method allows you to share your Streamlit applications easily without requiring your users to install Python locally. The process is straightforward, consisting of just three commands.
Step 1: Set Up Your Environment
Before you start, ensure you have the following installed on your machine:
- Node.js: This is required for Electron.
- Python: Make sure you have Python installed, as you'll be using Streamlit.
Practical Tips
- Check if Node.js is installed by running
node -vin your terminal. - For Python, use
python --versionto confirm its installation.
Step 2: Install Required Packages
You will need to install specific packages to facilitate the conversion process. Open your terminal and run the following commands:
-
Install Electron:
npm install -g electron -
Install Stlite: Stlite allows Streamlit to run in the browser context.
pip install stlite
Common Pitfalls
- Ensure you're running these commands in the correct environment (e.g., virtual environment for Python).
- If you encounter permission issues, consider using
sudofor the installation commands.
Step 3: Create Your Streamlit App
If you haven't already created a Streamlit app, do so now. Here’s a simple example of a Streamlit app:
import streamlit as st
st.title("My First Streamlit App")
st.write("Hello, world!")
Save this code in a file named app.py.
Step 4: Build the Executable
Now that you have your app ready, you can convert it into an executable. Run the following command in your terminal:
stlite build app.py
Additional Information
- The
buildcommand compiles your Streamlit app and prepares it for distribution. - Make sure to replace
app.pywith the name of your Streamlit file if it differs.
Step 5: Run Your Executable
Once the build process is complete, you can find your .EXE file in the output directory. You can run it by navigating to that directory and executing the file directly.
Practical Tips
- Test the executable on different machines to ensure compatibility.
- Share it with friends or family to demonstrate its functionality.
Conclusion
Converting a Streamlit app to an .EXE file is a quick and efficient way to distribute your applications. By following these steps, you can create executable files that allow users to run your apps without needing Python installed. This method, utilizing Electron and Stlite, makes sharing your projects seamless.
Next steps could include exploring more complex Streamlit features or enhancing your app's functionality before sharing it further.