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

Hi , I tried to do this with multiple streamlit apps but every time ,when i click the .exe file I get a white screen :

Unbelievable. I can´t believe it worked. Thanks

Are you running the streamlit server when opening the executable?

How did you deploy on MAC :smiley: ?

probably

on windows OS?

Hi,
What if the app is running on something else rather than streamlit cloud? does it work the same way?

1 Like

Hi, i would love to know how to run Streamlit Apps Natively On Android, can you help me ?

1 Like

Hi, this can also be an option to bundle a Streamlit app into a desktop app.
Please take a look :wink:

1 Like

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

Deleted because my solution wasn’t a solution afterall. It required you to have streamlit installed in your computer. The .exe wasn’t self-sufficient.

Unfortunately, I get an error message when I implement your solution @amml

but it communicates as if it were running in the cloud? Because my app pulls some things from the files in git and updates the “database”

Did you try running it in a different computer.

My application uses Data Base(a local database within the company) to generate reports. It is possible to make this app executable? Right now I get a connection error on streamlit share.

but when i send to another people, it said it had error where the ffmpeg is not found
how to i solve it?

@Super-MAN Thank you! been fiddling around for DAYS with pyinstaller, cx_freeze and what not only to randomly stumble upon this just now, gave it a shot thinking not much about it but it just worked!!!

But the app indeed needs to be deployed somewhere, either on streamlit or other place, so that the packaged WebApp can access your app. if you package your app using localhost:8501, then once you stop the server, the application would stop working as well.

Also, I don’t know how but this built app seems to run much faster than testing it on localhost!

This is amazing! thanks again!

Hi Superman,
I host the streamlit app locally with DDNS which work fine.
I can access the application where ever I found myself.
Can I still compile exe or I still need to host it in one of the streamlit clouds
Thanks

Hi,
It seems to (almost) work, when I launch the .exe, I have a blank window opening (not in browser), then a new tab in my browser where the app opens.
But then the app continuously opens in new tabs, until I close the blank window. Any solution for this, please?

I think this is not possible with a private repo