Debugging a Streamlit application in PyCharm on Windows
Asked Answered
D

1

5

I'm trying to setup a way to debug a Streamlit script in PyCharm. I'm on a Win10/64bit machine, working within an virtual environment created with conda. Running the code in the default way with streamlit run main.py works as expected. I have already read several forum posts and most importantly this related question on SO here.

My question is the following: The answer in the question above suggests to change the debug configuration to use Module name instead of Script path and enter streamlit.cli as module. Then in the parameters one should set run main.py as the argument.

Unfortunately this gets me the following error:

No module named streamlit.cli

Where do I find streamlit.cli shouldn't it be installed along with the default pip install of the library? Do I need to install it separately?

Any help is much appreciated!

Diarmid answered 20/9, 2022 at 7:15 Comment(0)
D
15

Stumbled across the (rather simple) answer by accident:

Simply use the "correct" module name, which in my case was streamlit instead of streamlit.cli. So for debugging I now have the following configuration:

  • Module Name (instead of "Script path"): streamlit
  • Parameter: run main.py
  • Interpreter options: not set
  • Working directory: <path\to\main.py>

As I have read in some streamlit forum post: "Works like a (Py)Charm!" :)

Diarmid answered 21/9, 2022 at 7:29 Comment(6)
Indeed, it works like a (Py)Charm!Lieb
This answer was really helpful for debugging a streamlit project using PyCharm.Cepeda
Does this method still work for the latest PyCharm? (I think it stopped working since 2023.3.x maybe. Definitely doesn't work in 2023.3.4). Error is TypeError("'Task' object is not callable"Consalve
@Consalve tbh I am not sure, I have since moved completely to VSCode. In case it doesn't work anymore, maybe create a new post or if you find an updated solution, add an answer here.Diarmid
@Consalve Did you find a solution?Defy
@aggsol, found this workaround youtrack.jetbrains.com/issue/PY-62467. Pretty much disable the setting "python.debug.asyncio.repl" in "Help | Find Action | Registry".Consalve

© 2022 - 2024 — McMap. All rights reserved.