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