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

Hi,

I am trying to test the default code for forms, and there is appearing the message: AttributeError: module ‘streamlit’ has no attribute ‘form’.

Below is the code (from Streamlit website).

with st.form("my_form"):
    st.write("Inside the form")
    slider_val = st.slider("Form slider")
    checkbox_val = st.checkbox("Form checkbox")

    # Every form must have a submit button.
    submitted = st.form_submit_button("Submit")
    if submitted:
        st.write("slider", slider_val, "checkbox", checkbox_val)

st.write("Outside the form")

Thank you.

Hi @Renan_Lopes, welcome to the Streamlit community!! :wave: :partying_face:

What version of the Streamlit library are you using? You can find out by including the following line above your st.form block:

st.write("Streamlit version:", st.__version__)

Or by running the following in your terminal:

streamlit version show

We released st.form and st.form_submit_button in Streamlit v0.81.1 in April 2021. :scream: If printing the version above confirms you’re running an older version, I highly recommend upgrading to the latest version to use all the cool features we’ve released since then.

To upgrade, run the following from your terminal:

pip install --upgrade streamlit
streamlit version

Source: How do I upgrade to the latest version of Streamlit? - Streamlit Docs

Happy Streamlit-ing! :balloon:
Snehan

Hi @snehankekre!

Yes, my version was 0.75.0. I updated according with your suggestion and it worked.

Thank you.

1 Like