0

I made a .py script converted it to a .exe file to make a windows desktop app using pyinstaller. I did this:

pyinstaller --onefile -w test.py

How can a user download this app using Streamlit? Specifically using Streamlit download button.

I tried st.download_button('Download app', data='app.exe', file_name='App.exe')

It won't work and the windows computer gives a blue box error (like when your battery is low) that say can't run this app. Probably because the argument data is a string not a file directory so I tried:

from pathlib import Path
exe_path = "drowsy_setup.exe"
path = Path(exe_path)
st.download_button('Download app', data=path, file_name='Drowsy_App.exe')

I added pathlib to requirements.txt file but it gives a error:

RuntimeError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs.
Traceback:
File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)
File "/app/website-desktop-app/test.py", line 15, in <module>
    st.download_button('Download app', data=path, file_name='Drowsy_App.exe')
File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/elements/button.py", line 212, in download_button
    self.dg._get_delta_path_str(), data, download_button_proto, mime, file_name
File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/elements/button.py", line 313, in marshall_file
    raise RuntimeError("Invalid binary data format: %s" % type(data))

I tried doing it without pathlib in requirements.txt as it is a default python library but it gives the same error. How do I fix this error? Is there a better way to download a desktop app using Streamlit?

versions: python(3.7), streamlit(1.3.0)

JoraSN
  • 332
  • 2
  • 14

1 Answers1

1

Try the following see also the doc.

binary_file = 'Drowsy_App.exe'

with open(binary_file, "rb") as file:
     btn = st.download_button(
         label="Download Drowsy_App.exe",
         data=file,
         file_name="Drowsy_App.exe",
         mime="application/octet-stream"
)
ferdy
  • 4,396
  • 2
  • 4
  • 16
  • I tried the code it works with a simple Hello World application printed on the terminal but it doesn't work for my actual application it still gives the can't run on computer error in a blue box(like a battery running low message). Probably it is a script error and not a Streamlit or Pyinstaller error so I am marking this answer as the accepted answer. I don't understand what's wrong with my script it worked perfectly locally. Forgot to mention I created a setup wizard for my app using Inno: https://jrsoftware.org/isinfo.php which is the .exe file I am trying to download from Streamlit website – JoraSN Jan 11 '22 at 04:27