Error importing hydralit: "ModuleNotFoundError: No module named 'streamlit.report_thread'"
Asked Answered
S

5

5

I installed Hydralit, but when I try to import I get the following error: "ModuleNotFoundError: No module named 'streamlit.report_thread'". Interestingly I can import and use hydralit_components.

Versions used:

hydralit >=1.0.9
hydralit_components >=1.0.4
streamlit >=0.89
python ==3.8.10

Error in full:

Python 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hydralit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lorena/.local/lib/python3.8/site-packages/hydralit/__init__.py", line 1, in <module>
    from hydralit.hydra_app import HydraApp
  File "/home/lorena/.local/lib/python3.8/site-packages/hydralit/hydra_app.py", line 5, in <module>
    from hydralit.sessionstate import SessionState
  File "/home/lorena/.local/lib/python3.8/site-packages/hydralit/sessionstate.py", line 1, in <module>
    import streamlit.report_thread as ReportThread
ModuleNotFoundError: No module named 'streamlit.report_thread'
Stockman answered 22/1, 2022 at 14:42 Comment(0)
D
4

I was able to make my problem go away by replacing

from streamlit.report_thread import add_report_ctx

with

from streamlit.script_run_context import add_script_run_ctx

(And, of course, replacing uses of add_report_ctx with add_script_run_ctx.)

I saw, however, on the streamlit discussion page, a question and answer on this problem, and they said this problem was introduced with 1.4 and to rollback to 1.3. So I am not sure what other problems may occur with my workaround. But I was able to make the import error disappear and a very quick test showed that it works.

Delila answered 28/1, 2022 at 6:0 Comment(2)
We are facing the exact same error !!, where exactly do we need to replace the add_report_ctx with add_script_run_ctx, in which specific submodule..Chinachinaberry
In your code where you are importing. I did not change streamlit code; I changed how I was using the streamlit code.Delila
O
1

The solution is to update to Hydralit version 1.0.12, as the issue with Streamlit 1.40 was fixed with the last release. pip install -U hydralit should take care of this issue.

Ossy answered 12/2, 2022 at 4:45 Comment(0)
T
1

In addition to what the user @Phil commented this change worked for me doing it the next way:

I changed the code of the package of hydralit in the sessionstate.py script.

If you are using a virtualenv, go to your-virtualenv-name/lib/pythonx.y/site-packages/hydralit/sessionstate.py.

If you are not using a virtual environment, find where is your package is installed and do the change there.

In the top part of the sessionstate.py file we change:

import streamlit
st_ver = int(streamlit.__version__.replace('.',''))

if st_ver < 140:
    import streamlit.report_thread as ReportThread
    from streamlit.server.server import Server
else:
    from streamlit.script_run_context import get_script_run_ctx    # Line to change

With:

import streamlit
st_ver = int(streamlit.__version__.replace('.',''))

if st_ver < 140:
    import streamlit.report_thread as ReportThread
    from streamlit.server.server import Server
else:
    from streamlit.scriptrunner import get_script_run_ctx     # Changed line

This solved my problems with the import of hydralit.

Versions of packages:

streamlit=1.9.0
HydraLit=1.0.12

Hope this helps others.

Tybie answered 28/5, 2022 at 10:48 Comment(0)
O
0

Hydralit has been updated to version 1.0.13, which now supports Streamlit >=1.9.

Ossy answered 22/6, 2022 at 23:55 Comment(0)
T
0

Running the following code in your terminal should work:

python3 -m pip install hydralit
Towill answered 16/9, 2022 at 18:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.