Languages‎ > ‎Python‎ > ‎

How to Configure Eclipse for Python


Once you have installed Eclipse, follow these directions to download Python and the Eclipse plug-in for Python, and then configure Eclipse to develop code on Python.

Make sure all required software is installed

  1. Eclipse 3.4
    The 2008-09 freshman laptops came with this version.
    1. If you need to install it, follow these instructions.
  2. Python 2.6
    The 2008-09 freshmen laptops came with Python 2.6.
    1. If you need to install it, follow these instructions.

Install the PyDev plug-in for Eclipse

  1. Launch Eclipse
    1. Launch Eclipse. A screen like this should appear, where you can choose which workspace to open. (If not, go to File → Switch WorkSpace → Other )

      The Launcher may not have this folder exactly but you can browse to it or type a similar name to create one (replacing the first xxx with your name and the second with the number of your course). Select "Use this as the default and do not ask again. If you do, Eclipse will automatically use this workspace next time you open Eclipse. If you want to change the workspace later you can always go to File → Switch Workspace... to be sent back to the Workspace Launcher window.

    2. You should now see Eclipse's Welcome screen:

      Click on the arrow on the right to go to the workbench.

      This is where you'll do most of your work in Eclipse.

  2. Download PyDev from within Eclipse
    1. Go to "Help > Software Updates..."
    2. You will now be shown a Software Updates and Add-ons screen. You may not see exactly the same items as shown below. 
      Select the "Available Software" tab.

    3. Select "Add Site".

    4. Enter "" under Location and click OK.

    5. Back in the "Available Software" tab, select the "Pydev" option (you may have to expand the "" root to see it). Do not select the "Optional Extensions" flag.

    6. Click "Install", verify that Pydev is selected in the next window. Then click "Next".
    7. Select "I accept the terms of the license agreement" then select "Finish". The installer will begin to download the plug-in. A window may appear asking you whether you want to install the plug-in. Select Install All.
    8. When the installation is complete, you will be asked if you want to restart Eclipse. Select Yes.
  3. Configure PyDev
    1. Go to "Window> Preferences". In the Preferences window, expand "Pydev" and select "Interpreter-Python".

    2. Click "New..." and type Python26 for the Interpreter name. For the Interpreter executable, browse to your copy of Python (probably C:\Program Files\Python26\python.exe), and press Open.

      The  "Selection Needed" Window will appear.

    3. Select all but the PySrc and and select OK as many times as necessary to exit the preferences.
    4. The Interpreter is now set up so that the code you write can be interpreted for the computer to run. You are now ready to start running code.

Writing Your First Python Program

  1. Switch to the Python perspective
    1. Go to "Window > Open Perspective > Other..." and choose "PyDev", then click OK. If you look at the upper right corner you will see that the perspective has changed from "Java" to "Pydev".

    2. Perspectives are designed to have the most useful tools within reach for whatever task you are doing (for example writing Java code or writing Python code). If you look in the "File> New" menu you will see that there are different options with the different perspective.

      Pydev Perspective
      Java Perspective

      As you can see, perspectives greatly affect the look of the Eclipse program.

  2. Create a new project
    1. Go to "File > New > PyDev Project" to start a wizard.
    2. In the next window that appears, enter the name of your project and select "python"  and 2.6"; as the type. Make sure "create default 'src' folder and add it to the pythonpath?" is selected. Click Finish.

    3. If you look at the upper left corner of the workspace (in the Package Explorer view), you should now see your newly created project with a "src" folder inside.

  3. Create a new module
    1. Select the project you just created and go to "File → New → Pydev Module". This will launch a new Pydev Module Wizard where you should enter a name for your module and make sure it is in the right location. Leave the Package field blank and select Finish.

    2. Look in the Package Explorer view and you will see an icon of your new file inside the src folder, which Eclipse created when you made the new project before.

      The file should be opened in the open space in the center of the workspace-the Editor view. (If not, right click on the icon and select Open.) You will see a tab with the name of your file.

  4. Write and run the program
    1. Here's a program to greet the world. Simply type print 'Hello, World!' into the file. You may remove the default doc comment or leave it there; Python ignores it.

    2. Right click on the file and select Save (or press Ctrl+S) to save the file.

    3. Finally, choose the icon, and go to "Run → Run As → Python Run" to run your program.

      (A quicker alternative is to right-click on the icon, and select "Run As > Python Run", or press F9.)

    4. Look at the bottom of your screen at the Console view and you will see the message you told the computer to print.

      Congratulations! You have written your first program with Python.

Configure PyDev for Productivity

  1. Add line numbers
    1. Add line numbers by right-clicking in the margin at the left side of the code view and click on Show Line Numbers
  2. Change the comment color to one you can read more easily
    1. Go to Window → Preferences. Open Pydev and select Editors. In the Appearance Color Options dropdown menu, select Comments. Then change it to a brighter color (perhaps lavender?).

  3. Turn on Task view  to show TODO: items and add a CONSIDER: tag
    1. Go to Window → Show View → Tasks.
    2. Window → Preferences → Pydev → Task Tags, and add CONSIDER: to the end of the list.
    3. To get the task tags to show, run the program once, or select Project → Clean

Configure PyDev for Running “Console” Programs

One left-over oddity from the days of the MS-DOS operating system, is that Windows uses a different convention to indicate the end of lines of input. Unix, Linux, and Mac OS X use a single byte (with value 13) to indicate the end of a line. Windows uses two bytes (10 and 13). Somehow the combination of Eclipse, PyDev, Windows, and Python causes problems for programs that required console input. Here are two options for avoiding that problem:

  1. Recommended: Add a small patch file to your Python package (We think this is only needed with pre-3.4 versions of Eclipse)
    • Place this file in the same folder where you put (probably something like c:\Program Files\Python25\Lib\site-packages).
    • At the beginning of your program file, add from win_in import *
    • Instead of the input() function, use win_input()
    • Instead of the raw_input() function, use win_raw_input()
  2. You can use the Console in Eclipse like the interactive shell in IDLE if you configure it correctly. This is only recommended for advanced Python users. If that’s you, then follow the directions here.