Saturday 6 April 2013

Python Development with PyDev in Eclipse



2.1. Python

Download Python from http://www.python.org. Download version 2.6.x from Python. If you are using Windows you can use the native installer for Python.

2.2. Eclipse Python Plugin

The following assume that you have already Eclipse installed. For an installation description of Eclipse please seeEclipse IDE for Java .
For Python development under Eclipse you can use the PyDev Plugin which is an open source project. Install PyDev via the Eclipse update manager via the following update site. http://pydev.org/updates .

2.3. Configuration of Eclipse

You also have to maintain in Eclipse the location of your Python installation. Open in the menu Window -> Preference and select Pydev-> Interpreter Python
Press new and maintain the path to "python.exe" in your installation directory.
The result should look like the following.

3. Your first Python program in Eclipse

Select File -> New -> Project. Select Pydev -> Pydev Project.
Create a new project with the name "de.vogella.python.first". Select Python version 2.6 and your interpreter.
Press finish.
Select Window->Open Perspective ->Other. Select the PyDev perspective.
Select the "src" folder of your project, right-click it and select New -> PyDev Modul. Create a module "FirstModule".
Create the following source code.
'''
Created on 18.06.2009

@author: Lars Vogel
'''
def add(a,b):
    return a+b

def addFixedValue(a):
  y = 5
  return y +a
  
print add(1,2)
print addFixedValue(1) 
Right-click your model and select Run As -> Python run.
able 1. Debugging Key bindings
CommandDescription
F5Goes to the next step in your program. If the next step is a method / function this command will jump into the associated code.
F6F6 will step over the call, e.g. it will call a method / function without entering the associated code.
F7F7 will go to the caller of the method/ function. So this will leave the current code and go to the calling code.
F8Use F8 to go to the next breakpoint. If no further breakpoint is encountered then the program will normally run.

No comments:

Post a Comment