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:
I want the app to be run locally, as we are dealing with private data
Colleagues should not need to have a Github account
No Python code should need to be run to launch the app
How can I best do this, something like Pyinstaller?
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.
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
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.
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:
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.
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!
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
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.
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!
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!
@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?!
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?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.