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

Hi @Edmilson_Philimone, @beep92,

The streamlit application acts as a frontend and backend, where the backend contains all the logic you put into the app. The Nativefier application grabs the generated frontend code (html, js, css) and puts it into Electron app. So it still depends on the backend to be running for all input and output to be processed. So the streamlit app will indeed need to be deployed somewhere in order for the nativefier application to work correctly.

My explanation might be a bit off here and there, but this is my understanding of it :slight_smile:.

3 Likes

Hello @maarten-betman,

You’re spot on; I researched the Nativefier application a bit right after, and it just extracts the frontend as an exe as you mentioned, not really extracting the full application - so I can’t use it anyways (not really a solution for offline use).

I’ll have to continue my research on making it fully usable offline as a deployed application :slight_smile: .

Appreciate your response!

3 Likes

Hi @beep92,

Good to know :slight_smile:

I dockerized a couple of streamlit application for offline usage (I work quite remote sometimes). Pulling the image will of course require internet, but there after should be no problem. If you don’t want to put the image on dockerhub there’s some pretty affordable private repo options or you can package the image as a tarball (I believe). For the less tech-savy users you can make a small batch script they can run once to get the container up for the first time, there after they can use the Docker desktop GUI to restart containers which is quite user friendly.

You’re awesome, thank you @maarten-betman.

I will give this a try tonight, that sounds interesting - it could work for me. I just saw that docker hub costs a small monthly fee to host private repos. I will test with some dummy code and if it works, it might be the best option for now.
My users are not tech-savy at all, so the batch file is probably the best way to go to launch the app. I’ll test this out as I’m not too familiar with docker yet. I’ll report back my results :slight_smile:

1 Like

Thanks its worked only with the final command i used
nativefier URL, however takes time to connect to streamlit server and every operation take more time

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?

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

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.