How to most easily share your streamlit app locally?

Hi everyone,

This questions might not be entirely specific to Streamlit, but it is still an important one as I want to easily share my Streamlit apps to colleagues. Some of the requirements that I have:

1. I want the app to be run locally, as we are dealing with private data
2. Colleagues should not need to have a Github account
3. No Python code should need to be run to launch the app

How can I best do this, something like Pyinstaller?

2 Likes

Hello @bjornvandijkman

I think a solution would be PyInstaller or PyOxidizer. I just tried to build a small Streamlit app with pyinstaller app.py but on running the app.exe I got :

pkg_resources.DistributionNotFound: The 'streamlit' distribution was not found and is required by the application
[11236] Failed to execute script app


but that was my first time using the library, maybe there are knobs to turn to configure the build process…

Other solutions I could think of :

• Seeing the requirements I guess the users are not tech-saavy, but is installing and running Docker containers on their machines a possibility ?
• I’m breaching the “locally” part but could you host your Streamlit app on a server and use the st.file_uploader so users can upload their private data and analyze it ? Each user should get their session and not access other people’s sessions.

In my institution we have a local server where all private data lives and the way I got around packaging the app was to write a .bat file that activates the base anaconda environment (which we all have in that server) and run the streamlit run app.py command.

I then created a shortcut icon for that .bat file so that my colleagues can just double-click it and poof! the app opens up a browser and it just works.

That’s another way of doing it ¯_(ツ)_/¯

Hope to share some steps，thanks

Hope to share some steps

This was my first time write a .bat file so it might be redundant but this is how it looks

set root=C:\ProgramData\Miniconda3\
call %root%\Scripts\activate.bat
call streamlit run "path\to\file\app.py"


after this i just created a shortcut icon to this file that i put in the shared project folder. You might not need to but it just makes it easier for non-technical colleagues

Hi @andfanilo and @chekos ,

Thank you for the suggestions and apologies for the delayed response.

I can get Pyinstaller to work with regular Python scripts. However, a missing argument in my executable file now is the call streamlit run app.py. According to @chekos I could include a .bat file to automate command line arguments, but I am not sure how I could create an .exe file in which such a .bat file is automatically executed.

My end goal is to have a single exe file that colleagues can execute without any restrictions.

Any help is appreciated!

Why not use subprocess.run(“streamlit run app.py”) in your wrapper python executable? That should build and deploy as an executable OK as long as you have Streamlit in your build requirements. If you need command line arguments to streamlit as well see the subprocess docs.

If you need to setup virtual environments and/or environment variables then you can use something like this (which has the same effect as the @chekos batch file) for the startup command:

cmd /c “conda activate appenv & setenv.bat & streamlit run apps/app.py”

Where setenv.bat sets the environment variables you need. All my environments run like this (I use ConsoleZ for DOS shells and each tab is started with an appropriate variant of the above cmd string).

For the 'live" server for my business users I use the same cmd layout in a batch file which is configured in Task Scheduler to startup with the machine.

This setup makes deploying and switching between environments very easy.

1 Like

I ended up using Pyinstaller with the subprocess.run command, which I ran from a different python file to not get stuck in an infinite loop haha. Thanks for the help guys!

1 Like

i have the same probleme.i create my application but i want to know how others uses it. for the moment I throw it from the cmd, however I close it from the cmd no one can use it

well for me an exe file was created using Pyinstaller that other users can click on. I suggest that you take a look at this video: https://www.youtube.com/watch?v=UZX5kH72Yx4

i check it

Some of these solutions will not cross-compile (i.e. if you have a Mac, Windows users won’t be able to run it), and are also susceptible to differences in the destination machine so they may not see exactly the same results.

A different approach, still involving only user-friendly software (i.e. GUIs) is using ContainDS which now supports Streamlit, so you can export a single ‘containds’ file to share with someone else who can import it directly to ContainDS running on their machine so the app runs exactly as intended.

It uses Docker underneath emulating an isolated Linux computer, allowing it to reproduce an identical environment.

I have written up a tutorial here: Share a Streamlit container as a File

2 Likes

Cool to hear that you made it work! Could you share in more detail, how you instruct pyinstaller to create the file and how your second .py file calls the streamlit command? Would like to copy your approach!

Great to hear that you make it work! I’m stuck in the samke problem. Could u share more details about how to config the Pyinstaller to make Streamlit work?
Cant wait to see your brilliant solution!

Hi guys,

So I have my main file with the code that I want to run (called main.py) which would look like something as follows:

import streamlit

def main():
# do stuff here

if __name__ == "__main__":
main()


and then another python file (run_streamlit.py) :

import subprocess
import other libraries that I use in main.py

subprocess.call(‘streamlit run main.py’)

And then I followed the tutorial which I linked to above and I believe called it on run_streamlit.py. Let me know if that worked out for you!

Thanks for your response! Calling the Streamlit main with streamlit.py works!
I had gotten an error trying PyInstaller just now, but I successfully compiled other apps with PyInstaller before. Will try to get that running in the next days. Will report back!

1 Like

@chekos: quick question here: if you saved your app in a common folder in server (which had python virtual environment installed there), the user will not be able to upload any files directly from his local right?
He’ll have to copy files from his local -> shared folder and then choose those files during streamlit is running? Is that right?

@bjornvandijkman - I agree with @andreas_rc. I was able to successfully run .py with subprocess.call. But when I converted this script to exe with pyinstaller - the exe creation was successful but when I tried running the .exe I got a fatal error, attached a screenshot. any gurus who can help here?!

Capture|450x237

I must admit, I also didn’t manage to get it running as an .exe /
The subprocess .py file works great, however packaging it with PyInstaller gave me various errors.
I would love to be able to share my app as one file, but PyInstaller seems to work only after tweaking the settings heavily. Or is there anything obvious we’re missing?