26

I'm new to python and I'm trying to use the interactive python debugger in the standard python package. Whenever I run "import ipdb" in my text editor (atom) or in the command line through iPython then I get the error: ImportError: No module named 'ipdb'

Where is my ipdb module? It's still missing after I reinstalled python.

Thanks!

Erin Wolpert
  • 363
  • 1
  • 5
  • 8

4 Answers4

32

pdb is built-in. ipdb you will have to install.

pip install ipdb
wim
  • 338,267
  • 99
  • 616
  • 750
12

ipdb comes with ipython, so if you already have ipython installed you can access it through that package using the following:

from IPython.core.debugger import Pdb
ipdb = Pdb()

Then you can use ipdb just as though you had done import ipdb, such as:

ipdb.runcall(self, func, *args, **kwds)
ipdb.run(self, cmd, globals=None, locals=None)
# etc.

If you don't have ipython installed, then you can just use pdb which is the built-in debugger. The main difference is ipdb has some extra bells and whistles.

Scott H
  • 2,644
  • 1
  • 24
  • 28
3

In the specific case that you want a more featureful ipdb debugger (including things like autocomplete), ipython also has one built-in (from what I can tell it's actually the one that ipython uses by default). Specifically, you can instead run

from IPython.terminal.debugger import TerminalPdb
ipdb = TerminalPdb()

and get the same features as the commands from @Scott H's answer, but now you get autocomplete in the debugger that comes up!

Josef
  • 2,869
  • 2
  • 22
  • 23
esg
  • 121
  • 6
0

If you installed using --user argument. You can check the executable name in ~/.local/bin. It's probably named ipdb3

$ ipdb
-bash: ipdb: command not found

$ ipdb3
usage: python -m ipdb [-c command] ... pyfile [arg] ...

Debug the Python program given by pyfile.
azzamsa
  • 1,805
  • 2
  • 20
  • 28