Difference between .py and .ipynb code execution

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.

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

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

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.

1 Like

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?

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?

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.

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

1 Like