CS 188: Artificial Intelligence, Spring 2007

Announcements Course Info Schedule/Slides Assignments FAQ Section Demos Newsgroup

Setting Up Eclipse for Python

What is Eclipse?

Eclipse is an integrated development environment (IDE) that provides an array of convenient and powerful code editing and debugging tools. For instance, Eclipse allows you to pause the execution of your code and investigate the values of all assigned variables. Such functionality will speed up your debugging process immensely.

Most of the Eclipse community uses the IDE to develop Java code (so you might be familiar with Eclipse even if you've never used Python). Because of this community bias, setting up Eclipse to edit Python code is slightly complicated. Eclipse requires the PyDev extension to properly develop Python code. This tutorial covers installing both Eclipse and Pydev, then walks through the basics of the Eclipse interface.

Other editors provide similar functionality, but we like Eclipse the best. You're not required to use it, but we certainly recommend that you do.

These instructions are ever-so-slightly tailored to installing on a Windows PC, but should work for Mac OS X or Linux as well.

Downloading Eclipse

You can download Eclipse here. The page should automatically detect your operating system. You want to download something called the "Eclipse SDK 3.2" (~120Mb).

Decompressing and opening should yield an Eclipse welcome screen. Amuse yourself with their tutorials and welcome messages as you wish. Then, Close the welcome screen to view the editor. You're now ready to install PyDev.

Installing PyDev

NOTE: If you're using your home computer, you first need an installation of Python, which you can download here.

Eclipse installs extensions for you from within the application. All you need to provide is the web address of the extension you want to add (in our case, PyDev).

Creating a Python Project

Eclipse organizes all of your code into projects. You'll want to create a new Python project for all of your CS 188 code.

Running Python from within Eclipse

Now you're ready to create a new python file and run it from within Eclipse. Right-click (control-click on Macs) on your project and create a new blank file. Make sure your file ends in .py, and Eclipse will recognize it as Python code.

Type in some Python code (for instance: print 2+2), then right-click on the Python file you've created and select Run As >> Python run . You should see the output of your Python code in the console at the bottom of the Eclipse window.

Now that you've run the code once, you can press the green Run arrow at the top of the Eclipse window to run it again.

The PyDev perspective

Your installation of Pydev also changes the contextual menus and layout of the Eclipse GUI to better suit Python development. To enable these enhancements, select Window >> Open Perspective >> Other... and then select the Pydev perspective. The changes you'll find are subtle; for instance you can create a new Python module by right-clicking on your project (instead of a generic file).


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. Eclipse should automatically change to a debugging perspective, which allows you to inspect variables in the upper right pane of the window.