What kind of error message do you get? In my case it helped to modify recursion limit, see below. You could also try to define matplotlib as hidden import. This was necessary for some packages that weren´t imported correctly by PyInstaller.
I took a different approach to this. I used pyinstaller to create the single file exe, but the resulting Python used was actually a separate install, not the one made by pyinstaller. That’s so that my users can create new streamlit apps and use new sections of the dependencies that I wasn’t using. (Given pyinstaller would have stripped those out).
To see a demo of the exe see:
When first clicking it, it will unpack the distro. Subsequent clicks should be much quicker to boot. I need to make the terminal give the user some details and provide functionality for updates etc. But in its current form it is usable.
The script used to make that exe can be found over at:
And here is the pyinstaller magic. The following script is what pyinstaller is pointed to. It sees if the full streamlit python distro has been extracted, if it has it boots up streamlit in there, if it hasn’t it extracts it before doing so:
This whole approach should be easier now that I suspect the following PR has just released within 0.72.0:
All that will be required now is changing the following line:
To calling “python.exe -m streamlit run path/to/your-app.py”
Very interesting, thank you for the step by step guide, I’ve managed to get it working!
However, can I check how long does your .exe take to load? Mine seems to take in excess of 1 minute, which seems pretty long. I’m already using a freshly created virtual environment, with only streamlit/pyinstaller installed.
I have created everything and followed your step by step guide. However when I have copied the files you mention in dist and then run the .exe file the app open in localhost:3000 so a different port than 8501.
My directory has all the relevant files and one folder called streamlit containing the config.toml file, and another one called hooks which has the hook-streamlit.py file.
May I ask:
- .streamlit/
- config.toml
- hooks/
the . in front of streamlit implies something different than the hooks? to my understanding streamlit and hooks are both folder in the directory of the project.
**when I run the run_main.py everything is executed as expected. The app opens in localhost:8501
Hey Guys thanks for the tutorial and files, sorry I’m a newbie, so I have downloaded the 2 files , and i have changed the “python.exe -m pymedphys gui” by " python.exe -m streamlit run C:/Users/belba/PycharmProjects/MLTEST2/appcopy.py"
I got this error message related to pyinstaller , any help plsssss
C:\Users\belba\PycharmProjects\MLTEST2\venv\Scripts\python.exe C:/Users/belba/PycharmProjects/MLTEST2/pyinstaller-bundle-script.py
Traceback (most recent call last):
File “C:/Users/belba/PycharmProjects/MLTEST2/pyinstaller-bundle-script.py”, line 94, in
main()
File “C:/Users/belba/PycharmProjects/MLTEST2/pyinstaller-bundle-script.py”, line 49, in main
_install(cwd, installation_path)
File “C:/Users/belba/PycharmProjects/MLTEST2/pyinstaller-bundle-script.py”, line 64, in _install
sys._MEIPASS # pylint: disable = no-member, protected-access
AttributeError: module ‘sys’ has no attribute ‘_MEIPASS’
I suspect that @Belbaly_Nassim is trying to use the work I underwent. Above you mentioned the following:
A benefit of the approach I underwent is it doesn’t let pyinstaller strip out the dependencies, and it is compatible with any Python library (exe creators don’t need to deal with pyinstaller incompatibility).
I don’t currently have the bandwidth to help @Belbaly_Nassim, but might you, @okld, have time to jump on a quick ~30 min video call, where I can describe what I have done and potentially you could carry the baton onwards?
@SimonBiggs, still working on the matter? Is your work available somewhere on github so I can quickly check the current status?
You can DM me on discourse to organize a call if needed.
In fact, I just picked it back up today and gave it a shot. I did hit a dead end though, so if you were interested in further troubleshooting that’d be amazing.
I tried the above solution by @hmasdev but I could not make it run yet.
When running pyinstaller --onefile --additional-hooks-dir=./hooks run_main.spec --clean I get the error that the file
‘{$MYCONDAENV}\Lib\site-packages\altair\vegalite\v4\schema\vega-lite-schema.json’
cannot be found.
I checked that the file exists but I think I need to change this part “{$MYCONDAENV}” in the spec file. Should I keep the “$” and the “{}”? Or should I replace {$MYCONDAENV} by the complete path?
EDIT:
After replacing “{$MYCONDAENV}” by the complete path I don’t get the error regarding the file vega-lite-schema.json any more. Now when starting run_main.exe it uses the port 3000 instead of 8501. Any idea what I might miss?
EDIT 2:
It was the “.” in “.streamlit”
It works now
The exe file gets pretty big though.
After trying this method on another streamlit app including data analysis tools like pandas and sklearn it turns out that in the executable file all processes are pretty slowed down which makes this method unfortunately not applicable for me
Would have been too nice to be true to be able to deploy web apps based on streamlit with this method
@SimonBiggs
Hi! I would be interested in a ~30 min video call to get the steps and potentially create a guide step-by-step for our peers. What do you say?
hi, @hmasdev
when i run run_main.exe i get the following error
raceback (most recent call last):
File “run_main.py”, line 4, in
AttributeError: module ‘streamlit.cli’ has no attribute ‘_main_run_clExplicit’
[26348] Failed to execute script ‘run_main’ due to unhandled exception!
although i defined this function in cli.py as follows
def _main_run_clExplicit(file, command_line, args=, flag_options={}):
streamlit._is_running_with_streamlit = True
bootstrap.run(file, command_line, args, flag_options)
Wow I had no clue there’s such a massive conversation going on on the very topic I’m interested in figuring out! @SimonBiggs I’d be happy to get on that call please just let me know when and where. Although, fair warning, I’m only useful as your “dummy check”, i.e. “is this simple enough for a dummy to figure out” as the extent of my programming knowledge is far behind everyone else here
On a separate note, and I genuinely hope my tone is not misunderstood, why is this entire process not as easy as just adding a few lines of code at the start of the program? I mean something like:
And maybe have this code replace the entire process of running the cmd “streamlit run XYZ.py” so whenever you run your code, it goes through the entire process? And also, I believe this makes it so just making an exe out of your python would make it a standalone app that launches the server and does all the stuff we are all trying to achieve here?
I mean, in my unprofessional opinion, I just find the whole process of opening a terminal and writing the cmd to launch streamlit somewhat unnecessary. What is the reason that that is required and it cannot be done any other way? I mean I do make a batch file that runs the command automatically, but I’m just tired of forgetting to change the name of the python file when I save my program as a new version, and end up wondering for an hour why every tweak that I made is not showing up before I realize the batch file launched an old version of the code
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.