How to debug Jupyter notebooks in PyCharm ?

Answered

I am able to run all the cells in the Jupyter notebook in PyCharm.

I want capability for debugging these Jupyter notebboks.
Like adding breakpoints and checking for variables values when the cell is being executed.

 

6 comments
Comment actions Permalink

Hi Guruswaroop45! I am sorry for the inconvenience, but unfortunately it's not possible yet, please vote for PY-14742.

0
Comment actions Permalink

Well, have you tried to attach the python process of the notebook into PyCharm? With this approach, you can set PyCharm breakpoints in python scripts imported by the notebook (not on the notebook itself, though). More on this at https://medium.com/@marc.wouts/debug-jupyter-notebooks-with-pycharm-91004080fbd5

-1
Comment actions Permalink

That attach thing doesn't work, it just returns after a while and doesn't get to my breakpoint

0
Comment actions Permalink

Hi Peter, I'm sorry it did not work in your case. Indeed the configuration is not trivial.
Yet I've been using this on Linux for months, and on Windows for weeks, thus I think there's a reasonable chance that it should work for you as well.

May I recall the main steps for this?
- start a jupyter notebook server (outside of PyCharm)
- move the function you want to debug to a python script
- configure pycharm to use the same python environment than the kernel used by jupyter. List of kernels is with `jupyter-kernelspec list`, and kernel details, including path to python executable, are in the `kernel.json` file in the kernel directory
- set a breakpoint in the python script, in PyCharm
- import the script in the notebook (re-start and run the notebook to make sure the newly defined function is taken from the script)
- execute %connect_info in Jupyter
- attach PyCharm to the matching kernel
- and finally, call the desired function in the notebook

Please let me know which step exactly doesn't work, I'd be interested in knowing which part is not well documented in my tutorial.

 

 

0
Comment actions Permalink

+1 for this feature.

0
Comment actions Permalink

Please try 2019.1 release. New Jupyter support comes with a native debugger out of the box.

0

Please sign in to leave a comment.