# Failed to run slicer codes in PyCharm, what's wrong with my settings?

**URL:** <https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015>\
**Category:** Support\
**Created:** [January 30, 2020, 3:47am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015 "2020-01-30T03:47:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [January 30, 2020, 3:47am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/1 "2020-01-30T03:47:54Z")

</div>

Operating system: Tried both Windows10 and Linux Ubuntu  
Slicer version:4.10.2  
Expected behavior:Run and debug slicer in PyCharm using codes from [https://github.com/Slicer/SlicerNotebooks/blob/master/01\_Data\_Loading\_and\_Visualization.ipynb](https://github.com/Slicer/SlicerNotebooks/blob/master/01_Data_Loading_and_Visualization.ipynb)  
following [https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools)  
Actual behavior:  
Always being not able to run codes,

pydevd\_pycharm.settrace(‘localhost’, port=4567, stdoutToServer=True, stderrToServer=True)  
Waiting for process connection…  
Connected to pydev debugger (build 193.5233.109)  
Expected: %s to exist.  
None

---

<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:** [January 30, 2020, 3:58am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/2 "2020-01-30T03:58:13Z")

</div>

You don’t run code. Slicer runs code that are in scripted modules or that you type in the Python console and if you put a breakpoint in the code then you can do step-by-step debugging from there.

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [January 30, 2020, 4:01am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/3 "2020-01-30T04:01:27Z")

</div>

Hi Iassoan,

Thank you for your reply.  
But I cannot understand. I am not able to type anything in the Python console:

 ![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/4/6469e252e0a295bcf7fc2783660586c259de3683.png)

Could you please let me know what should I do in detail?

---

<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:** [January 30, 2020, 4:07am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/4 "2020-01-30T04:07:53Z")

</div>

It seems that you missed this step described in the [instructions page](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools#Start_debugging): “Important: once Slicer is paused at a breakpoint, you can open a terminal, where you can enter Python commands (you have access to all Slicer variables, it has auto-complete, etc). Click the small terminal icon _Show Python Prompt_ to open the Python console.”

[![](https://www.slicer.org/w/img_auth.php/a/a2/PyCharmDebugConsole.png) ](https://www.slicer.org/w/img_auth.php/a/a2/PyCharmDebugConsole.png)

If you click that button (the second from the bottom) then the output window turns into an interactive Python console.

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [January 30, 2020, 4:25am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/5 "2020-01-30T04:25:12Z")

</div>

> [@lassoan](#):
>
> once Slicer is paused at a breakpoint

How to pause in Slicer? I did not find a “pause” button, nor being able to add a breakpoint in the Slicer. 😅

---

<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:** [January 30, 2020, 4:29am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/6 "2020-01-30T04:29:18Z")

</div>

Pause option is in the “Run” menu. If you click it then Slicer will break as soon as it executes some Python code.

Slicer will also pause automatically at any breakpoints that you added (this is the usual way of pausing the program).

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [January 30, 2020, 4:42am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/7 "2020-01-30T04:42:25Z")

</div>

So sorry that I am not able to find it. 😂  
😅  
Could you please show a screenshot of the “Run” menu and “Pause” option in Slicer?  
Thank you very much!

---

<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:** [January 30, 2020, 4:46am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/8 "2020-01-30T04:46:34Z")

</div>

It’s here:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/d/7d73f030b7e96c45e9c8df53fb7078b1cc6ad77a.png)

But as I wrote, it is rarely used and instead you normally pause by inserting breakpoints.

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [March 9, 2020, 10:55pm UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/9 "2020-03-09T22:55:14Z")

</div>

Hi Iassoan,

I am now able to manually type into the PyCharm python console after pausing the program.  
However, I have no idea how to debug a script. All I can do now is to copy the code one line by one line every time I want to run something. 😅

Could you please let me know, how could I run a script while being able to debug with breakpoint without using extension wizard introduced in the tutorial example?

Thank you very much!

---

<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:** [March 9, 2020, 11:47pm UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/10 "2020-03-09T23:47:08Z")

</div>

You have several options.

1. Copy-paste code line-by-line to the Python console in Slicer

2. Use SlicerJupyter module to use Slicer as a Jupyter kernel. No need to copy-paste, you can run a cell at a time (it is easy to split/merge cells). You can combine this with method 1.

3. Put your code into a Slicer module (you can change the code without restarting Slicer: save the changes then save the file hit Reload button in Slicer) and insert a breakpoint where you want to start step-by-step debugging. You can combine this with method 1 and even method 2.

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [March 10, 2020, 1:06am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/11 "2020-03-10T01:06:56Z")

</div>

Hi Iassoan,

To use PyCharm for debugging, is the “Extension Wizard” under “Developer Tool” the only way to add a new Module? And is it also the only way to debug a script in PyCharm?

---

<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:** [March 10, 2020, 1:26am UTC](https://discourse.slicer.org/t/failed-to-run-slicer-codes-in-pycharm-whats-wrong-with-my-settings/10015/12 "2020-03-10T01:26:50Z")

</div>

> [@Illusion](#):
>
> To use PyCharm for debugging, is the “Extension Wizard” under “Developer Tool” the only way to add a new Module? And is it also the only way to debug a script in PyCharm?

Creating a skeleton module (where you can copy-paste your script into) using Extension Wizard should not take more than a few minutes. Doing manually would take more time and would be more error-prone, so I would recommend using Extension Wizard. You might be able to run script from a file manually (using importlib), but reloading might be a bit tricky, and again, this is simpler using the module template, which shows a Reload (and Reload&Test) button, which reloads the file by a single click.
