Set_page_config problem


StreamlitAPIException : set_page_config() can only be called once per app, and must be called as the first Streamlit command in your script.

Steps to reproduce

Code snippet:

import streamlit as st
from st_pages import Page, Section, show_pages, add_page_title

st.set_page_config(page_title="OGT Web Toolbox",
def main():
    """Main function"""

            Page("src/", "OGT Web Toolbox", "๐Ÿงฐ"),
            Section(name=" tools"),
            Page("src/other_pages/", " Batch Estimator", "๐Ÿงฎ"),
           ...[removed for brevity]

I have a streamlit app with multiple subpages setup as seen above.

Initialy I had a st.set_page_config on each subpage and I thought the error I was having was related to that.

However, I have not removed all of those instances and still streamlit complains about
set_page_config() being called multiple times and not being the first Streamlit command in myscript.

What am I doing wrong?


Debug info

  • Streamlit version: Streamlit, version 1.21.0
  • Python version: Python 3.10.9
  • Using Conda
  • OS version:
  • Browser version:

Hi @duartemolha :wave:

Have you searched through your whole codebase to ensure that st.set_page_config() was indeed only called once?



I donโ€™t get an error with your code snippet. You can call set_page_config on each page of your app. On the page where you get the error, check any imports that occur before you use set_page_config as something might be happening there. (Same if you have imports later on the page or functions that might have something buried.)

I ran your snippet on 1.21.0 and 1.20.0 without a problem using Python 3.10.10 (after removing the redaction and adding a line to call main()). I used the latest version of st_pages.

Can you provide a complete, minimum working snippet to trigger the error?


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