Starting Streamlit from Python - ReportContext

Hey everyone.
I am trying to start the Streamlit from the python file. After first start, I have started the get the error of ReportContext and nothing starts. Since Streamlit will work from another engineering program, I need to start it from the python file. Can you add some magical codes and make it work?

import sys
from streamlit import cli as stcli
import streamlit as st
 
   
def main():
# Your streamlit code
    st.title("Trial")

if __name__ == '__main__':
    if st._is_running_with_streamlit:
        main()
    else:
        sys.argv = ["streamlit", "run", sys.argv[0]]
        sys.exit(stcli.main())

Hey @Berk_Demir, can you please refer to this. Hopefully it answers your question.

@abhi7585
Thank you for your answer. However, the code I have posted above is taken from there directly with little modifications. My problem is related to ReportContext error.

I followed the steps mentioned in that post and was able to achieve the same. I think you should wait someone might be able to resolve your issue shortly.

If not too much trouble, can you please use my code above, run the code (streamlit opens), close the browser and run the code again. I think since we cannot close it properly (since we do not start in cmd), there is a problem. Do you see the same problem?

2021-02-23 12:05:33.307 Thread ‘MainThread’: missing ReportContext
2021-02-23 12:05:33.309 Thread ‘MainThread’: missing ReportContext

I am very lost in ReportContexts, SessionStates etc. I just want to start the Streamlit from Python. Any help?

See the same errors when attempting: import steamlit

Did a little digging, looking at pip install logs, I see references too python 2.7. Opened Python 2, import streamlit worked. Streatlit commands started to work.

Appears something is wrong with the python 3 implementation. that is causing the error:
AttributeError: module ‘google.protobuf.descriptor’ has no attribute ‘_internal_create_key’

Can try running from Python 2, hopefully the Python 3 error will be fixed. A warning, Python 2 is no longer supported. I would attempt anything critical.

Oh really? Very strange. I’ll not go back to Python 2. Where should I file the bug report?