Run streamlit from PyCharm

Hi,
I used to run and debug streamlit (version below 1.0) from PyCharm as a module according to this manual:
stack overflow: How to run/debug a streamlit application from an IDE

TL;DR:
PyCharm runs streamlit as:

python -m streamlit.cli run app.py

Now I have updated streamlit to version 1.5 and it does not work anymore:

File "/some/path/python3.8/site-packages/streamlit/cli.py", line 214, in _get_command_line_as_string
    assert parent.command_path == "streamlit"
AssertionError

Is there a quick fix or is this way of running streamlit not supported anymore, as the assertion now requires that streamlit is run from the streamlit executable?

1 Like

Hey @schilli,

This is a bit of a fun story. We actually didn’t realize there was a pretty large group of people (mostly PyCharm and VSCode users) running streamlit via python -m streamlit.cli <command>. This method was discovered by the community and seems to have spread through the StackOverflow post that you linked, but internally we never really considered it a “supported” method (it’s undocumented so isn’t considered part of our public API. It just so happens that you used to be able to run the submodule to get functionality equivalent to using streamlit run <command>).

A very similar and equivalent way of invoking streamlit that is supported (so has guarantees to not be broken in the future) is to simply run:

python -m streamlit <command>

instead. Alternatively, another way of running streamlit from PyCharm is described here: Version 1.5.0 - #11 by tim

We’re discussing this internally since it is unfortunate that we inadvertently broke some people’s dev envs, and while a decision hasn’t been finalized, it sounds like we’ll likely keep things as-is (but improve the error message / add official documentation for setting up Streamlit with PyCharm/VSCode) since

  • it feels a bit weird adding official support for a way of invoking streamlit that we never intended to officially support (my guess is that that particular file is only runnable because it made it easier to build/debug when streamlit was first being built, and we just forgot to remove those lines)
  • it’s not too much effort to just remove the .cli so that streamlit is now being started using a supported method
2 Likes

In Pycharm i run streamlit like i would through a terminal as Pycharm gives you good terminal access.

But that is not as nice for debugging for example!

Hi @vdonato,
Great answer, I really appreciate your effort!
I just tried your solution of removing the .cli and it works like a (py)charm :grin:!
Cheers
Oliver

1 Like

Can confirm running through Pycharm is very nice, especially for debugging. Removing cli is working for me too.


anyone can you help with the problem here