I am trying to run this simple code to test the session state, but every time I run it I get the same error (see below). I have read already about several issues like this, but the solutions do not suit to me
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “c:\Users\thomas\Desktop\python_codes\regenschreiber_frontend\teste_render.py”, line 12, in
st.write('Count = ', st.session_state.count)
File “C:\Users\thomas\AppData\Roaming\Python\Python310\site-packages\streamlit\runtime\state\session_state_proxy.py”, line 121, in getattr
raise AttributeError(_missing_attr_error_message(key))
AttributeError: st.session_state has no attribute “count”. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docs
Steps to reproduce
Code snippet:
import streamlit as st
st.title("Counter Example")
if "count" not in st.session_state:
st.session_state.count = 0
increment = st.button("Increment")
if increment:
st.session_state.count += 1
st.write('Count = ', st.session_state.count)
Thank you for the fast reply, but even with your code, the app does not initialize. See the error below:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “c:\Users\thomas\Desktop\python_codes\regenschreiber_frontend\session.py”, line 11, in
if st.session_state.clicked:
File “C:\Users\thomas\AppData\Roaming\Python\Python310\site-packages\streamlit\runtime\state\session_state_proxy.py”, line 121, in getattr
raise AttributeError(_missing_attr_error_message(key))
AttributeError: st.session_state has no attribute “clicked”. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docs
PS C:\Users\thomas\Desktop\python_codes\regenschreiber_frontend>
I had the same issue - but after going bonkers for a few mins I realized I was trying to run it as a regular python script (python streamlit_app.py) instead of streamlit run streamlit_app.py
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.