Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to link iPython notebooks and PyCharm, especially regarding debugging?

iPython notebooks and PyCharm have complementary features, so I'm switching a lot from one to the other. But I would like to make the relationship tighter.

For example, when I'm in a notebook and some code blows up, I would like to set a break point in PyCharm, run my code snippet again, and explore the variables in the breakpoint's scope.

At this point, when I'm in this situation I have to either:

  1. Use the debug command in the notebook, but the navigation within this debugger is a bit clunky (no context autofill, no back-history, no function help display... basically, it seems I'm not in a notebook anymore!)
  2. Go to PyCharm, write a script to recreate the same environment (i.e. imports, variables with their values, etc.) as I was in in the notebook, and launch debug on that script.

This is the main use case I'd like to see solved. Of course, things like triggering PyCharm's "find usages" and "jump to definition" from iPython notebook itself would be a charm (pun not initially intended), but I'll curb my desires for the perfect IDE. For now.

like image 574
thorwhalen Avatar asked May 26 '14 17:05

thorwhalen


People also ask

How do I debug a Jupyter notebook in PyCharm?

Debug code in Jupyter notebooksSet the breakpoints in the selected cell and press Alt + Shift + Enter for Windows or ⌥⇧↩ for macOS. Alternatively, you can right-click the cell and select Debug Cell from the context menu. The Jupyter Notebook Debugger tool window opens.

How do I debug in IPython notebook?

The easiest way to debug a Jupyter notebook is to use the %debug magic command. Whenever you encounter an error or exception, just open a new notebook cell, type %debug and run the cell. This will open a command line where you can test your code and inspect all variables right up to the line that threw the error.

Can PyCharm run IPython?

PyCharm supports usage of IPython magic commands. Prior to start working, consider the following prerequisites: IPython is available on your computer with Anaconda. The corresponding Conda environment is set as the default interpreter for the current project.


1 Answers

PyCharm 4.0 just came out with iPython integration and allows you to edit *.ipynb files. The official notes are here. Here's how it looks on my screen:

enter image description here

like image 85
Will Avatar answered Oct 27 '22 13:10

Will