How to run/debug a streamlit application from an IDE

I found a way to at least run the code from the IDE (PyCharm in my case). The streamlit run code.py command can directly be called from your IDE. (The streamlit run code.py command actually calls python -m streamlit.cli run code.py, which was the former solution to run from the IDE.)

The -m streamlit run goes into the interpreter options field of the Run/Debug Configuration (this is supported by Streamlit, so has guarantees to not be broken in the future1), the code.py goes into the Script path field as expected. In past versions, it was also working to use -m streamlit.cli run in the interpreter options field of the Run/Debug Configuration, but this option might break in the future.

PyCharm Run configuration shown here

Unfortunately, debugging that way does not seem to work since the parameters appended by PyCharm are passed to streamlit instead of the pydev debugger.

Edit: Just found a way to debug your own scripts. Instead of debugging your script, you debug the streamlit.cli module which runs your script. To do so, you need to change from Script path: to Module name: in the top-most field (there is a slightly hidden dropdown box there…). Then you can insert streamlit.cli into the field. As the parameters, you now add run code.py into the Parameters: field of the Run/Debug Configuration.
Run/Debug configuration shown here

EDIT: adding @sismo ‘s comment

If your script needs to be run with some args you can easily add them as

run main.py -- --option1 val1 --option2 val2

Note the first -- with blank: it is needed to stop streamlit argument parsing and pass to main.py argument parsing.


1 https://discuss.streamlit.io/t/run-streamlit-from-pycharm/21624/3

Leave a Comment