我有一个streamlit应用程序,当我“streamlit run myapp.py”时运行良好,没有任何错误。但是,当我使用 pyinstaller 创建 exe 并运行该 exe 时,出现错误“消息格式错误,在初始化之前尝试使用 SessionInfo”。在控制台中,错误为
ERROR:asyncio:Exception in callback AppSession._on_scriptrunner_event.<locals>.<lambda>() at streamlit\runtime\app_session.py:473
handle: <Handle AppSession._on_scriptrunner_event.<locals>.<lambda>() at streamlit\runtime\app_session.py:473>
Traceback (most recent call last):
File "asyncio\events.py", line 81, in _run
File "streamlit\runtime\app_session.py", line 473, in <lambda>
lambda: self._handle_scriptrunner_event_on_event_loop(
File "streamlit\runtime\app_session.py", line 543, in _handle_scriptrunner_event_on_event_loop
self._create_new_session_message(page_script_hash)
File "streamlit\runtime\app_session.py", line 660, in _create_new_session_message
imsg.is_hello = self._script_data.is_hello
TypeError: an integer is required (got type str)
app_session.py 第 468-477 行是:
This is generally called from the sender ScriptRunner's script thread.
We forward the event on to _handle_scriptrunner_event_on_event_loop,
which will be called on the main thread.
"""
self._event_loop.call_soon_threadsafe(
lambda: self._handle_scriptrunner_event_on_event_loop(
sender, event, forward_msg, exception, client_state, page_script_hash
)
)
每当我在 ui 中进行更改时,我都会遇到同样的错误,但一切都按预期工作。
为了在 pyinstaller 中运行 Streamlit 应用程序,我创建了一个 .spec 文件:
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['myapp.py'],
pathex=[],
binaries=[],
datas=[
(
"./venv/Lib/site-packages/altair/vegalite/v5/schema/vega-lite-schema.json",
"./altair/vegalite/v5/schema/"
),
(
"./venv/Lib/site-packages/",
"."
),
(
"./*.py",
"."
),
],
hiddenimports=[
"streamlit",
"streamlit-extras"
],
hookspath=['./hooks'],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='myapp',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='my_app',
)
你能展示一下myapp.py代码吗?