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 greatly. Eclipse (and IDEs like it) are important tools in modern software engineering. Warning: make sure you read and understand the notes regarding file handling with eclipse in step (4) and (8) below. Some students have accidentally submitted empty (template) files because of misreading these steps.

(1) Download and Install Python

Note: the computers in Soda already have python installed. Your computer might too. You can download and install Python from the Python website. Versions 2.5 and 2.6 will both work for this course. The version that is guaranteed to be most compatible with the autograder and instructional machines is Python 2.6.6 (note that this is NOT the latest version, or even the latest version of the 2.x series, or even the latest version of the 2.6.x series!). Python 2.6.7 will work as well, but does not have a Windows installer. Python 2.7.2 is likely also okay, but using its 2.7.x features in your code may cause problems for the autograder. Do not use Python 3, as it is not backwards compatible and will not work with the autograder.

(2) Download & Install Eclipse

You can download Eclipse here. The page should automatically detect your operating system. You want to download the "Eclipse Classic".

Decompressing and opening should yield an Eclipse welcome screen. Close the welcome screen (close tab in upper left) to view the editor. You're now ready to install PyDev.

(3) Install PyDev

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).

  1. A. From the menu system, select Help >> Install New Software... >> Find and Install...
  2. B. Select the Add... button on the top right
  3. C. Enter the following details and click Ok :
    PyDev
    http://pydev.org/updates
  4. D. PyDev will appear in the list, select it and click Next > twice.
  5. E. Accept the license agreement and press Next > to install PyDev. The basic Pydev is free and gives syntax highlighting and other helpful tools.
  6. F. Open the Preferences window within Eclipse and select Pydev >> Interpreter - Python"
  7. G. In the top of the preferences pane, click New... and locate your installation of Python.
  8.  

(4) Creating a Python Project

Eclipse organizes all of your code into projects, which by default are create in sub-directory of the workspace directory. You'll want to create a new Python project for each assignment. Once it is created, you can locate the location of your project in your filesystem by right-clicking on the project name and selecting "Properties". You can copy over the template in your empty project. You need to right click on the project name and select "Refresh" to see the filesystem changes reflected in eclipse. You can also drag and drop files directly into eclipse, but this creates a copy of the file into the project folder in eclipse's workspace rather than moving the file---keep that in mind when you submit your files in step (8).

(5) 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.

(6) The PyDev perspective

Your installation of Pydev also changes the contextual menus and layout of the Eclipse GUI to better suit Python development. If you did not choose to open the PyDev perspective when prompeted by eclipse in the previous step, 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).

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

(8) Submitting

Make sure you submit your working copy, and not the empty template you downloaded. Again, you can locate your working copy filesystem location by right-clicking on the project name and selecting "Properties".