python - How to debug external .py functions run from Jupyter/IPython notebook -


my jupyter/ipython notebook executes functions in external .py.

i need set breakpoints within these functions, inspect variables, single step, etc.

it isn't practical use combination of print statements , throwing exceptions early-exit cell.

i need kind of workflow.

is possible hook third-party editor/ide view .py , somehow connect python runtime jupyter/ipython using?

so if set breakpoint in external .py using ide , execute cell in notebook encounters said breakpoint, can continue navigate manually within ide.

edit: i've found https://pypi.python.org/pypi/ipdb https://www.quora.com/what-are-your-favorite-tricks-for-ipython-notebook

edit https://www.youtube.com/watch?v=jb2hhoahvce <-- video getting close i'm after, can't quite see how put together. video demonstrates spyder ide ipython prompt... wonder if maybe can run notebook through prompt , debug it.

edit: looks though pycharm i'm after: https://www.jetbrains.com/help/pycharm/2016.1/tutorial-using-ipython-jupyter-notebook-with-pycharm.html

edit: i'm in middle of trying pycharm behave. provide details in answer if sort out.

is possible hook third-party editor/ide view .py , somehow connect python runtime jupyter/ipython using?

yes, it's possible.

using emacs third party python ide.

you can open file side-by-side ipython runtime. possible send definitions external file directly prompt using key shortcuts, , set breakpoints, single step , inspect variables ipython prompt using standard python debugger pdb.

auto-completion works fine. writing import xxx makes emacs aware of functions within xxx module.

here example screenshot: spacemacs

and these steps followed screenshot.*

  1. open file playground.py on emacs.
  2. press c-c c-p fire ipython process , connect file it. note ipython process functional. can call magic methods on it.
  3. press m-m m d b include breakpoint in line want (in form of pdb import)
  4. press c-m-x send definition ipython prompt. note in screenshot calling unique_everseen without ever having typed prompt. definition sent directly file (that why have empty cell 2, visual feedback emacs did something).
  5. execute function ipython prompt trigger breakpoint. information telling me line , enter debugger automatically.
  6. i inspect variables see going on.
  7. i press n step next instruction.
  8. i click on filename (displayed in red on prompt) , takes cursor directly line within playground.py file. note black triangles next line numbers telling me stepper in. pretty nice.

now, i haven't scratched surface of emacs can offer. if interests i'd suggest looking it. it's powerful , has great, helpful , active community.

to python configuration running out of box without having configure install spacemacs, popular distribution of emacs (what anaconda python, spacemacs emacs). install instructions can found under link.

using emacs edit ipython notebooks.

a package called ein (emacs ipython notebooks) "provides ipython notebook client , integrated repl in emacs." working open ipython notebook server terminal ipython notebook, , call function ein:notebooklist.

more information can found under project's page here, , on spacemacs ipython-notebook layer page here.

in particular, ein documentation:

  1. copy/paste cells, to/from different notebooks.
  2. console integration: can connect kernel via console application. enables start debugging in same kernel. possible connect console on ssh.
  3. an ipython kernel can "connected" emacs buffer. enables evaluate buffer or buffer region using same kernel notebook. notebook goodies such tooltip help, browser , code completion available in these buffers.
  4. jump definition (go definition hitting m-. on object).

all functionality described above simple ipython + file workflow available ipython notebooks (*.ipynb).

screenshots here.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -