Error regarding st.set_page_config

Whenever i run the streamlit intially i getting the below error

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

after refreshing the page the error is gone and im using the set_page_config()` only once in the script

Hi there,

Thanks for sharing your question with the community! Check out our guidelines on how to post an effective question here and please update your post to include a code snippet (+ what version of Streamlit you’re running) so we can try to reproduce the issue.

import streamlit as st
import os
from utils import*
import pandas as pd
import numpy as np
import pandas as pd
from dtaidistance import dtw
import mass_ts as mts
from bokeh.plotting import figure, output_file, show
import as px
import matplotlib.pyplot as plt
import math
import as pio
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import copy
from golden_batch import *
from Polluted import *
from PIL import Image
import warnings

st.set_page_config(page_title=“Dashboard for Batch Analysis”,layout=“wide”)


if nav == “Batch-Analysis-1”:

col1, col2, col3, col4 = st.columns(4)

with col1:
    if 'batch_cond' not in st.session_state.keys():
        batch_condObj = cUpload("Choose a file for Non-Golden batch")
        batch_cond = batch_condObj.FileuploadDisplay()
        batch_condObj =  st.session_state['batch_cond']
        batch_cond = batch_condObj.FileuploadDisplay()

You are calling st.set_page_config() in another module too. Don’t do that. As the error message says, you can call st.set_page_config() only once.

yes i know, but i didnt use that in any other module.

I cannot think of any other explanation.

My guess, which is purely a guess since I can’t see the other files in your repository, is that you have some streamlit commands being run in your utils module, so that when you do from utils import *, it actually runs st.<something>. Can you check all of the modules you’re importing from, and see if there are st commands running in them? If so, you could put those inside a function so they won’t run just by importing the module.


Thanks for that hint, yes that is what was occurring for me. I moved that code to just after the import of streamlit and the issue went away.

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