# Difference between .py and .ipynb code execution

**URL:** <https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215>\
**Category:** Support\
**Tags:** python\
**Created:** [July 6, 2022, 10:59pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215 "2022-07-06T22:59:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbaheti](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rbaheti](https://discourse.slicer.org/u/rbaheti)\
**Post date:** [July 6, 2022, 10:59pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/1 "2022-07-06T22:59:59Z")

</div>

Hi,  
I’ve been executing sitk commands using Jupyter Notebook (.ipynb) and it’s been working perfectly. As a next step I’ve to execute the python code on Matlab using pyrunfile() command. This requires the code to have a .py extension. But the same code doesn’t work on Spyder (.py). Any particular reason for this?

By best guess where the code fails is while executing Geodesic Active Contour.

---

<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:** [July 7, 2022, 12:43am UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/2 "2022-07-07T00:43:28Z")

</div>

It seems that these questions are not related to Slicer. You may try to ask for help on Matlab forums.

---

<div class="post-metadata">

**Author:** ![rbaheti](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rbaheti](https://discourse.slicer.org/u/rbaheti)\
**Post date:** [July 7, 2022, 4:18pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/3 "2022-07-07T16:18:01Z")

</div>

Hi @lassoan  
The problem isn’t with matlab execution. The code fails on Spyder - with or without matlab being used.

---

<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:** [July 7, 2022, 4:47pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/4 "2022-07-07T16:47:01Z")

</div>

Any code that you can run in some stock Python environment (in the Python console, in Spyder, or in any other Python IDE) then it should work well in 3D Slicer’s virtual Python environment. If you encounter any problem doing this then let us know.

---

<div class="post-metadata">

**Author:** ![rbaheti](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rbaheti](https://discourse.slicer.org/u/rbaheti)\
**Post date:** [July 7, 2022, 5:51pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/5 "2022-07-07T17:51:01Z")

</div>

I’ve tried to look for a solution for this online but bore unfruitful results. The problem still remains: The same code works on Jupyter (.ipynb) but not on Spyder (.py). What can I do to fix this?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [July 7, 2022, 5:52pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/6 "2022-07-07T17:52:08Z")

</div>

What is the specific failure in the code execution? Is there a traceback? Are you trying to `import slicer` outside of the slicer python environment?

---

<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:** [July 7, 2022, 6:16pm UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/7 "2022-07-07T18:16:36Z")

</div>

> [@rbaheti](#):
>
> The same code works on Jupyter (.ipynb) but not on Spyder (.py)

This is the forum of `Slicer` (medical image analysis and visualization software) not `Spyder` (Python IDE). Maybe you have mistakenly posted your question here.

If you think the problem is with SimpleITK then you can ask about it on the [ITK forum](https://discourse.itk.org/).

---

<div class="post-metadata">

**Author:** ![rbaheti](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@rbaheti](https://discourse.slicer.org/u/rbaheti)\
**Post date:** [July 8, 2022, 2:49am UTC](https://discourse.slicer.org/t/difference-between-py-and-ipynb-code-execution/24215/8 "2022-07-08T02:49:16Z")

</div>

Solved the issue. It wasn’t an issue with Slicer or Spyder - I just rebooted the system and it worked.
