Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make 'interact' use IPython console, rather than standard Python one?

In pdb/ipdb debugging, the useful interact command gives me a fully featured interactive Python console.

However, this appears to always be the "standard" Python console, even if I use ipdb to begin with. Is there a way to configure ipdb such that interact will give me the IPython console, rather than the standard Python one? Interestingly, I do get the IPython style prompt, but I don't get to use IPython magic such as %whos:

In [24]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-24-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: division by zero

In [25]: %debug
> <ipython-input-24-05c9758a9c21>(1)<module>()
----> 1 1/0

ipdb> interact
*interactive*
In : %whos
  File "<console>", line 1
    %whos
    ^
SyntaxError: invalid syntax

Is there a way to get ipdbs interact to give me the fully featured IPython console?

like image 479
gerrit Avatar asked Aug 19 '14 23:08

gerrit


People also ask

How do I open IPython console in terminal?

You start IPython by typing “ipython” in your terminal. $ ipython Python 2.7.

What is the difference between Python and IPython?

The ease of use of Python and its dynamic nature make it a very productive language. IPython is an interactive command-line terminal for Python. It was created by Fernando Perez in 2001. IPython offers an enhanced read-eval-print loop (REPL) environment particularly well adapted to scientific computing.

What is IPython console?

The IPython Console allows you to execute commands and interact with data inside IPython interpreters. To launch a new IPython instance, go to New console (default settings) under the Consoles menu, or use the keyboard shortcut Ctrl - T ( Cmd - T on macOS) when the console is focused.

How do I run a Python program in IPython?

You can use run command in the input prompt to run a Python script. The run command is actually line magic command and should actually be written as %run. However, the %automagic mode is always on by default, so you can omit this.


1 Answers

In .pdbrc:

import IPython 
[..]
# Interactive shell
alias interacti IPython.embed()
like image 156
dimid Avatar answered Oct 26 '22 03:10

dimid