Hello,

I just cannot manage to package a simple Streamlit app (a library for 
creating browser-based GUIs). I have read through all the material on the 
Pyinstaller website and the Github wiki.
 
This is my main.py:

import streamlit as st

st.text("This program is running")

and this is my wrapper.py:

import subprocess
from pathlib import Path
import sys

def resource_path(relative_path):
try:
base_path = Path(sys._MEIPASS)
except AttributeError:
return relative_path
return base_path.joinpath(relative_path).as_posix()

main_script_path = resource_path("main.py")

with open('streamlit_output.txt', 'w') as f_out, 
open('streamlit_error.txt', 'w') as f_err:
subprocess.run(f'streamlit run "{main_script_path}"',
stdout=f_out, stderr=f_err, check=True, shell=True)

Running this wrapper locally works. 

To package it with Pyinstaller I first run pyi-makespec --onedir -w 
--additional-hooks-dir=hooks --add-data "main_st.py;." 
--hidden-import=streamlit --debug=all wrapper_st.py.

My hook-streamlit.py looks like this:

from PyInstaller.utils.hooks import copy_metadata, collect_submodules

datas = copy_metadata("streamlit")
hiddenimports = collect_submodules('streamlit')

I then modify the spec file datas section as follows (some people online 
said that this was necessary):

a = Analysis(
['wrapper_st.py'],
pathex=[],
binaries=[],
datas=[('main_st.py', '.'),
('C:/Users/jusc_da/venvs/airfucs-calc-311/Lib/site-packages/altair/vegalite/v5/schema',
 
'./altair/vegalite/v5/schema'),
('C:/Users/jusc_da/venvs/airfucs-calc-311/Lib/site-packages/streamlit/static', 
'./streamlit/static')],
...

Finally I build the exe by running pyinstaller wrapper_st.spec --clean 
--noconfirm.

When double clicking the resulting exe, nothing happens. The 
streamlit_error.txt file contains:

'streamlit' is not recognized as an internal or external command,
operable program or batch file.

What am I doing wrong?




-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/836e9560-56ba-4130-82bf-d302b1cd97a8n%40googlegroups.com.

Reply via email to