2

I usually debug a python script with the help of the ipdb debugger by putting the following line into the source code:

import ipdb; ipdb.set_trace()

Then when I run the script, ipdb starts. Very often I need to plot numpy arrays in an interactive graph using matplotlib plotting library. I use the following commands to make interactive plotting possible inside the ipdb:

import matplotlib.pyplot as plt
plt.ion()

My question is whether it is possible to run these two commands automatically when ipdb starts.

Dmitry Kabanov
  • 710
  • 1
  • 7
  • 20

1 Answers1

4

I am currently looking at how to fix this in ipdb (loading the user configuration and init scripts). But for now there is a solution which I discovered reading the pdb documentation.

If you place a .pdbrc file in your home or at the root of your project directory, the script will be executed in the pdb shell (which also works for ipdb).

Here is the issue I am currently working on: https://github.com/gotcha/ipdb/issues/61

IxDay
  • 3,667
  • 2
  • 22
  • 27
  • 1
    @lxDay, I saw the github issue you mentioned.. When I put the following statement `from IPython import embed` in my `.pdbrc` and then when in `ipdb` I issue `embed()`, I dont actually have a `IPython` shell come up. Is this still supposed to work? – alpha_989 Jun 04 '18 at 17:23
  • I am using `0.10.3` version of `ipdb`. – alpha_989 Jun 04 '18 at 17:24
  • 1
    @alpha_989 you need to alias it, e.g. another line in your `.pdbrc` like `alias ipython embed`. Then you can use `ipython` in `(i)pdb`. – C S Aug 16 '18 at 16:23