How to debug the function in PyCharm called from IPython in web browser (Chrome)?

Answered

In PyDev, I can debug the function called from IPython in Chrome in the following way.

step 1. open the python file in PyDev (for example, test.py ). step 2. set the breakpoint from code in PyDev editor

test.py

using pydevd 
def my_add(a, b):
   a = 1
   settrace()              ## break point here 
   b = 2  
   return a+b  

step 3. In PyDev, open debug server (push a button)

step 4. In browser of the IPython page, run the code to call my_add().

import test
my_add()

step 5.PyDev will stop at the breakpoint PyDev will enter step-by-step debug model. Then, I can debug as normal python file.

Question: When using PyCharm (2016.2), I cannot find similar function to open debug server. Can anyone give me some suggestions on how to debug code in PyCharm called from IPython in the browser (Chrome).

1
4 comments

Hello! Could you please clarify, do you mean debugging of connected ipython notebook? If so, unfortunately it's not possible yet, please vote for the existing feature request https://youtrack.jetbrains.com/issue/PY-14742 to increase its priority and be notified about updates.

1
Avatar
Permanently deleted user

It is different from that feature you mentioned.The scenario is as following.

For the data processing work, I write the complex algorithms in *.py files with PyCharm. Then, I call these functions and plot results in IPython in the web browser. I want to debug the function in *.py file using PyCharm when I run the function from IPython.  I can do this using PyDev, but I do not know how to do this in PyCharm.

Thanks for your swift reply!

1

Do you use this functionality in PyDev: http://www.pydev.org/manual_adv_remote_debugger.html? If so, there is a similar option in Pycharm, please check: https://www.jetbrains.com/help/pycharm/2016.3/remote-debugging.html#6.

0
Avatar
Permanently deleted user

Thanks! It currently works for me.
It is a bit different to PyDev. When setting the breakpoint by "pydevd.settrace()", the URL and port number should be set as the same in the Remote debug configure dialog. For me, I call pydevd.settrace('localhost', port=3897) . In PyDev, I just use the default value, just call pydevd.settrace(). Hope this will help the people have the similar problem.
Thank you so much for your help.

0

Please sign in to leave a comment.