# Debugging a python script in pycharm

**URL:** <https://discourse.slicer.org/t/debugging-a-python-script-in-pycharm/36585>\
**Category:** Development\
**Tags:** python, debug\
**Created:** [June 4, 2024, 11:07am UTC](https://discourse.slicer.org/t/debugging-a-python-script-in-pycharm/36585 "2024-06-04T11:07:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RomanStriker](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@RomanStriker](https://discourse.slicer.org/u/RomanStriker)\
**Post date:** [June 4, 2024, 11:07am UTC](https://discourse.slicer.org/t/debugging-a-python-script-in-pycharm/36585/1 "2024-06-04T11:07:49Z")

</div>

Hi,

I have a python script that I would like to debug step by step. I managed to attach Pycharm’s remote debugger to Slicer using these [instructions](https://github.com/SlicerRt/SlicerDebuggingTools#instructions-for-pycharm), however, I cannot run the python script in the Slicer GUI’s python console in debugging mode. The only way I have managed to run the script in debugging mode is by creating a custom module and add my code to the onApply() function of the module and press the Apply button. Is there a simpler way to debug python scripts?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 4, 2024, 4:10pm UTC](https://discourse.slicer.org/t/debugging-a-python-script-in-pycharm/36585/2 "2024-06-04T16:10:18Z")

</div>

The debugger needs a file. So, copying your code snippet into a module is a good approach.

If you work with a code snippet (not saved in file) then you don’t need a debugger, as you can run the code step-by-step anyway.
