Tutorial: Setting up a python debugging environment in Eclipse

As being a savvy programmer, it is vital to have a debugger along with the development. Today I spent two+ hours configuring the python debugger in the Eclipse IDE. (Yes, i feel a need to set it up as i just started dealing with the massive python scripts at my work). After nailing it down i would like to share how I set up.

Prerequisites:

1) Eclipse IDE installed. (At the time of writing, I am using Eclipse Luna 4.4 version)
2) Pydev Eclipse plugin installed. (http://pydev.org/download.html)

Then, depends on which way we want, we can do:
–To debug a remote program
1) Inside the Eclipse, start the remote debug server. If we don’t find it in the tool bar, we can go to Window > Customize perspective > Command groups availability > PyDev debug

2) In the external python script, put these two lines at the begining:

import sys;sys.path.append(r’/Users/ken/eclipse/plugins/org.python.pydev_3.0.0.1388187472/pysrc’) #assuming this is the pydev installation path
import pydevd

3) In the external python script, put this line anywhere you want to have the program paused at the debugger:
pydevd.settrace();

3) Inside the Eclipse, go to the debug perspective

4) there you go, you should be able to pause the execution at where you put the statement at in step 3) above

–To debug a program inside a Eclipse
This is much more easier than debugging a remote program. It is pretty much like debugging a java program in Eclipse.

1) Create a debug configuration: Go to Run -> Debug Configurations -> Python Run, create a profile accordingly

2) Hit Debug

Advertisements

One thought on “Tutorial: Setting up a python debugging environment in Eclipse

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s