Streamlit Erroring Out With SystemExit: 0

104 Views Asked by At

Context:

I have the following code that implements a @click.command and I am calling the command programmatically and want to show the output as a streamlit header using st.header

import streamlit as st
import click

st.header("hi")

@click.command()
@click.option("--rating", type=int, default=5, help="The rating of the movie")
@click.argument("like")
def show_rating(rating, like):
    print(f"The movie has a rating of {rating}")
    print(f"The movie is likeable: {like}")


st.header(show_rating(["True", "--rating", "8", ]))

For some reason, streamlit errors out with the following error:

SystemExit: 0
Traceback:
File "d:\program files\anaconda3\lib\site-packages\streamlit\script_runner.py", line 333, in _run_script
    exec(code, module.__dict__)
File "D:\Users\Jamil\Desktop\Python\Meta\Streamlit\ui.py", line 16, in <module>
    st.header(show_rating(["True", "--rating", "8", ]))
File "d:\program files\anaconda3\lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
File "d:\program files\anaconda3\lib\site-packages\click\core.py", line 1081, in main
    sys.exit(e.exit_code)

I narrowed down the error to this line

st.header(show_rating(["True", "--rating", "8", ]))

Why does error occurs in streamlit but the terminal showing me the results when I print it?

Terminal output:

enter image description here

1

There are 1 best solutions below

0
On

Because you passed a wrong argument to show_rating which is , at the very last of the list.

Change:

st.header(show_rating(["True", "--rating", "8", ]))

To:

st.header(show_rating(["True", "--rating", "8"]))