Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm just figuring out how to run the command streamlit run APP_NAME.py with a python script, which might look like:

import streamlit

streamlit.run("APP_NAME.py")

I can't securely depend on a call to os.system(...) or subprocess.

1 Answer

0 votes
by (26.4k points)

I guess this works, I investigated the genuine streamlit document in my python/conda bin, and it had these lines:

import re

import sys

from streamlit.cli import main

if __name__ == '__main__':

    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])

    sys.exit(main())

From here, you can see that running streamlit run APP_NAME.py on the order line is the equivalent (in python) as:

import sys

from streamlit import cli as stcli

if __name__ == '__main__':

    sys.argv = ["streamlit", "run", "APP_NAME.py"]

    sys.exit(stcli.main())

So I put that in another content and afterward run that content to run the first application from python, and it appeared to work. I don't know how cross-platform this answer is, however, as it actually depends fairly on command line args.

Want to learn python to gain more knowledge? Come and join the python training course

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...