TangleSpace / hydralit

A library to create multi-page Streamlit applications with ease.
Apache License 2.0
202 stars 19 forks source link

Import Syntax Issues With Streamlit 1.12.2 #44

Closed code49 closed 2 years ago

code49 commented 2 years ago

Trying to build a website using Hydralit, and encountered ModuleNotFound errors immediately upon importing the library.

It seems like at some point Streamlit changed around their code schema; changing two lines in sessionstate.py seemed to do the trick:

# from
from streamlit.scriptrunner.script_run_context import get_script_run_ctx

# to
from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx

and

# from
from streamlit.server.server import Server

# to
from streamlit.web.server import Server

I'm pretty new to Streamlit/Hydralit, but hopefully these changes won't break anything else? Seems to be working just fine from the testing I've been doing.

code49 commented 2 years ago

After some more digging, it seems like these changes would also introduce issues around getting the sessionstate for a specific session_id (perhaps the functionality of Server has changed?); working on potential solutions now.

As a side note, this seems to be the part of the same-ish issue as #43 , so perhaps the fix to that will fix these import path issues as well.

saikumarmk commented 2 years ago

Yes, the way the streamlit server imports worked before was that it used a hack to obtain a state, which is now deprecated. The Server class no longer has a method called get_current, which breaks Hydra anyway. See this forum post on Streamlit 1.12 breaking functionality: https://discuss.streamlit.io/t/streamlit-script-run-context-gone-with-1-8/23526/5. Fishing the Server instance from the GC is hacky.

I've been working on refactoring Hydralit to use the built-in session_state, which removes the need for the sessionstate.py file entirely.

saikumarmk commented 2 years ago

Update:

I've put in a PR for a rewrite that works with Streamlit >=1.12. You can check it out at #45. I've only tested it with hydralit_example though.

TangleSpace commented 2 years ago

please update to the latest package (1.0.14), as a fix has been created and deployed.

pip install -U hydralit

Thanks very much for your hard work saikumarmk!