Рубрики
Без рубрики

Использование Python IPDB из Jupyter

Как использовать отладчик Python IPDB из ноутбука Jupyter. Помечено с Python, программированием, отладки.

(Этот блог пост изначально появился в моем блоге https://www.andreagrandi.it/2016/05/10/using-python-ipdb-from-jupyter/ )

Если мы попытаемся использовать обычные команды IPDB из Jupyter (ноутбук iPython)

import ipdb; ipdb.set_trace()

Мы получим аналогичную ошибку:

-------------------------------------------------------------------------------
MultipleInstanceError                     Traceback (most recent call last)
 in ()
    1 a=4
---------> 2 import ipdb; ipdb.set_trace()
    3 b=5
    4 print a
    5 print b

/home/nnn/anaconda/lib/python2.7/site-packages/ipdb/__init__.py in ()
    14 # You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
    15 
--------> 16 from ipdb.__main__ import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
    17 
    18 pm                       # please pyflakes

/home/nnn/anaconda/lib/python2.7/site-packages/ipdb/__main__.py in ()
    71         # the instance method will create a new one without loading the config.
    72         # i.e: if we are in an embed instance we do not want to load the config.
--------> 73         ipapp = TerminalIPythonApp.instance()
    74         shell = get_ipython()
    75         def_colors = shell.colors

/home/nnn/anaconda/lib/python2.7/site-packages/traitlets/config/configurable.pyc in instance(cls, *args, **kwargs)
    413             raise MultipleInstanceError(
    414                 'Multiple incompatible subclass instances of '
--> 415                 '%s are being created.' % cls.__name__
    416             )
    417

MultipleInstanceError: Multiple incompatible subclass instances of TerminalIPythonApp are being created.

Решением является использование траслера вместо этого:

from IPython.core.debugger import Tracer
Tracer()()

Источник: http://stackoverflow.com/questions/35613249/using-ipdb-to-debug-python-code-in-on-cell-jupyter-in-ipthon.

Оригинал: “https://dev.to/andreagrandi/using-python-ipdb-from-jupyter-5g3f”