Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python debugging in Eclipse+PyDev

I try Eclipse+PyDev pair for some of my work. (Eclipse v3.5.0 + PyDev v1.5.6) I couldn't find a way to expose all of my variables to the PyDev console (Through PyDev console -> Console for current active editor option) I use a simple code to describe the issue. When I step-by-step go through the code I can't access my "x" variable from the console. It is viewed on Variables tab, but that's not really what I want.

Any help is appreciate.

See my screenshot for better description:

alt text

EDIT:

Assume adding a simple func like:

def myfunc(x):
    return x**x

When I debug with the function added in the code I can access myfunc from the console easily. (Type myfunc and it will be available after this automatic execution:

>>> from part2.test import myfunc
>>> myfunc

Then when I do myfunc(5) it acts just like in the Python interpreter. It would be so useful to access variables in the similar fashion for debugging my code. I have big arrays and I do various tests and operations during debug process. Like: Get my x and do x.sum(), later do x[::10], or transpose operate with other arrays observe results, experiment etc...

Hope there will be a better solution.

like image 394
Gökhan Sever Avatar asked Apr 24 '10 15:04

Gökhan Sever


People also ask

How do I debug Python code in Eclipse?

Debugging. You can add breakpoints to your code by double clicking in the gray bar to the left of the editing pane within the Eclipse window (a blue dot will appear). Then, to pause the code at that location and inspect the value of variables, select Debug As >> Python Run or click the bug at the top of the screen.

How do I use PyDev debugger?

Use Ctrl+F10 to open the context-menu and then select Add Breakpoint; Right-click the left bar to open the context-menu and then select Add Breakpoint; Use Ctrl+Shift+B to toggle the breakpoint in the line (if it doesn't work, go to the customize perspective and enable Breakpoints in Action Set Availability.

How do I run Python in PyDev?

Configure PyDevGo to Window → Preferences. In the Preferences window, expand PyDev and select Interpreter-Python. Click "New..." and type Python32 for the Interpreter name. For the Interpreter executable, browse to your copy of Python (C:\Program Files\Python32\python.exe), and press Open.


1 Answers

Update:

In the latest PyDev versions, it's possible to right-click a frame in the stack and select PyDev > Debug console to have the interactive console with more functions associated to a context during a debug session.


Unfortunately, the actual interactive console, which would be the preferred way of playing with code (with code-completion, etc -- http://pydev.org/manual_adv_interactive_console.html) has no connection to a debug session right now (this is planned but still not implemented).

Still, with the 'simpler' console available, you are still able to interactively inspect and play with the variables available in a breakpoint scope: http://pydev.org/manual_adv_debug_console.html (which is the same as you'd have with pdb -- it's just a matter of typing code in the available console after a breakpoint is hit).

Cheers,

Fabio

like image 170
Fabio Zadrozny Avatar answered Sep 30 '22 19:09

Fabio Zadrozny