ModuleNotFoundError: No module named 'streamlit.report_thread'

I’m trying to deploy an object detection web app on streamlit cloud but it’s throwing me this error

File “/home/appuser/venv/lib/python3.7/site-packages/streamlit_webrtc/session_info.py”, line 1, in
import streamlit.report_thread as ReportThread

the app runs fine on my local setup

here is the github repo of the project

here is the piece of code from the file which i think throws the error

import pandas as pd
import PIL.Image as Image
import tensorflow as tf
import tensorflow_hub as hub
import cv2
import urllib

import asyncio
import logging
import queue
import threading
import urllib.request
from pathlib import Path
from typing import List, NamedTuple

try:
    from typing import Literal
except ImportError:
    from typing_extensions import Literal  # type: ignore

import av
import matplotlib.pyplot as plt
import numpy as np
import pydub
import streamlit as st
from aiortc.contrib.media import MediaPlayer

from streamlit_webrtc import (
    AudioProcessorBase,
    RTCConfiguration,
    VideoProcessorBase,
    WebRtcMode,
    webrtc_streamer,
)
1 Like

Hello @Aditya_Chache, welcome to the community!

We’ve seen the issue appear this morning with the new 1.4.0 release, for now if you are in a hurry you can downgrade back to streamlit==1.3.1.

Do you use any old Session State code or external Streamlit package aside from streamlit-webrtc ? That will help the team diagnose the problem.

PS: wait, I think, @whitphx are you calling streamlit.report_thread in streamlit-webrtc ? I submitted an issue ModuleNotFoundError: No module named 'streamlit.report_thread' on Streamlit 1.4.0 · Issue #598 · whitphx/streamlit-webrtc · GitHub

Have a nice day,
Fanilo

2 Likes

Thank you so much for solving the problem.
I just downgraded back to version 1.3.1 and now everything works fine

Hi, thank you for the report.
I updated streamlit-webrtc and released a new version.
streamlit-webrtc>=0.34.1 should work with streamlit==1.4.0.

4 Likes

we unfortunately have the same error on both 1.4 and 1.5 - maybe streamlit aggrid needs an update too? (no webrtc in our case)

1 Like

I’ve been using the same API to get the session UUID. What’s the alternative to get session id now?

2 Likes

FYI,
here is my implementation to get the session id.

1 Like

Hello,

I am trying to use threads in an MQTT connection (on_connect and on_message). I was trying to use this solution to be able to use streamlit inside the threads (as seen in Live plot from a thread - #12 by hcoohb). But I get the following error:

AttributeError: module ‘streamlit’ has no attribute ‘ReportThread’

Is it due to the new version of streamlit ? I have tried downgrading it to 1.3.0 and it does not change the error

def connect_mqtt():

    KEY_CONTEXT = st.ReportThread.REPORT_CONTEXT_ATTR_NAME
    main_context = getattr(current_thread(), KEY_CONTEXT)

    def on_connect(client, userdata, flags, rc):
        thread = current_thread()
        if getattr(thread, KEY_CONTEXT, None) is None:
            setattr(thread, KEY_CONTEXT, main_context)
        if rc == 0:
            print("Connected to MQTT Broker!")
        else:
            print("Failed to connect to MQTT broker, return code %d\n", rc)

    def on_message(client, userdata, msg):
        thread = current_thread()
        if getattr(thread, KEY_CONTEXT, None) is None:
            setattr(thread, KEY_CONTEXT, main_context)
       
        st.session_state["message"] = "Save message received from MQTT broker"

        print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
        print("message received ", str(msg.payload.decode("utf-8")))
        print("message topic=", msg.topic)
        print("message qos=", msg.qos)
        print("message retain flag=", msg.retain)

    client = mqtt_client.Client(client_id)
    client.username_pw_set(username, password)
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect(broker, port)
    return client
1 Like

as the issue persists, can we reopen the issue as unsolved or do you want us to open a new thread?

If you are having a similar issue, I would suggest starting a new thread, as commenting on a thread that was originally solved for the first user often gets ignored (because, people see it as a solved issue).

Hey @andfanilo ,

I wanted to take up this issue as I am also facing the same challenge.

When I upgrade to streamlit 1.4.0 or 1.5.0, we get an error: No Module named “streamlit.report_thread”.

I am using streamlit-analytics and was using SessionState old code. After removing SessionState old code, streamlit-analyticss seems to pose the problem while deploying.

Currently, I reverted back to 1.3.1 and it is working fine.

I see there’s a PR waiting on ReportThread - ModuleNotFoundError · Issue #14 · jrieke/streamlit-analytics (github.com); maybe you can ping there to get the merge done sooner than later :slight_smile:

Fanilo

2 Likes

Have same issue with streamlit 1.8.1, having tried workaround by @whitphx, get report_thread not found. Any further workarounds? Thanks!

Edit: Found this suggestion by @velicanu resolved:

from streamlit.scriptrunner import add_script_run_ctx

Yes the snippet I posted above was for Streamlit 1.4 at the time and not compatible with 1.8 now.

My current implementation compatible with Streamlit 1.8 is below.

2 Likes

@whitphx We are facing the same issue when we upgraded to 1.9, we are also using streamlit analytics along with extracting sesion_state, not sure where should we make the change you suggested in your solution, could you provide some guidance

@av_abhishiek streamlit_analytics should be fixed as it seems to be using the old version API.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.