Streamlit Deployment as an Executable File (.exe) For Windows MacOS And Android

Hi everyone, after collecting all tips from this thread, and making some changes here and there plus some additions, I managed to get this working (meaning, using PyInstaller to produce an executable for my streamlit app). The app is quite complicated, so I detailed the steps for a rather simple app below.

To test this, create the two files below: app.py and run.py.

app.py

import streamlit as st
import pandas as pd

if st.button("CLICK ME"):
    df = pd.DataFrame({
        "Name": ["John", "Mary"],
        "Age": [23, 34]
    })
    st.dataframe(df, use_container_width=True)

run.py

# Import here all modules that your app import explicitly, otherwise PyInstaller will not know they
# are needed and produce an executable that complains about "ModuleNotFoundError".

import pandas
import streamlit

# These imports are needed for the streamlit execution below.
import streamlit.web.cli as stcli
import sys


if __name__ == "__main__":
    sys.argv=["streamlit", "run", "app.py", "--global.developmentMode=false"]
    sys.exit(stcli.main())

Now, call PyInstaller as shown below (note the options!):

pyinstaller --copy-metadata streamlit --collect-data streamlit run.py

Once this is step finished (it can take a minute or so), your executable can be found under dist/run/run (in Windows, it should be dist\run\run.exe). Change run by any other name you want.

Hope this works for you as it did for me (at least as of today, Nov 2nd, 2023!)

OS: Ubuntu 20.04
Package versions:

streamlit                 1.13.0             pyhd8ed1ab_1    conda-forge
pyinstaller               5.1             py310ha400145_1    conda-forge