AttributeError: module 'streamlit' has no attribute 'session_state'


When I executed streamlit run, I got the following error.

AttributeError: module 'streamlit' has no attribute 'session_state'

Before I got the error…

(1) composed as follows

import streamlit as st

import select_page as page1
import show_page as page2
import scraping_page as page3

pages = {

if "news" not in st.session_state:
    st.session_state["news"] = {}
if "sites" not in st.session_state:
    st.session_state["sites"] = {}

selection ="", list(pages.keys()))

if selection == "対象サイトの選択":
    is_scraping_list = pages[selection]()
elif selection == "新着情報一覧":
elif selection == "更新の実行" :
    news_dict = pages[selection]()
    st.session_state["news"] = news_dict

(2) executed streamlit run

I got the following error message.

AttributeError: module 'streamlit' has no attribute 'session_state'
File "/Users/toshiaki/anaconda3/envs/Campus-Dog/lib/python3.8/site-packages/streamlit/", line 337, in _run_script
    exec(code, module.__dict__)
File "/Users/toshiaki/workspace/Campus-Dog/", line 17, in <module>
    if "news" not in st.session_state:

I thought empty dictionaries would be in sessions whose keys were news and sites.
Because documentation says as follows.

if ‘key’ not in st.session_state:
st.session_state[‘key’] = ‘value’

Session State also supports attribute based syntax
if ‘key’ not in st.session_state:
st.session_state.key = ‘value’

I thought I could access to session data using st.session_state so I mimicked them in my

My development environment is like this:
MacOS Big Sur
Streamlit 0.81.1
Python 3.8.8
package management using Anaconda

This trouble has been solved by upgrading streamlit to the latest version 0.84.0