Tuesday, 7 July 2009

Sledgehammer, meet nut - Using Eclipse for Python

I usually use gvim or IDLE to edit Python files, but today I thought I'd try something a bit more heavyweight: Eclipse. Eclipse is widely used in the Java world. It's open source and freely available, and most importantly there is a Python plugin for Eclipse called PyDev.

So what does Eclipse have that IDLE doesn't? Well, integration with the Python debugger for a start. Also, this sort of code completion is quite handy (click for a larger image):
It also has nice integration with PyLint (see the bottom pane in the following figure) which catches various errors (e.g. mispelled variables) before you run a script:
Here are some notes:
  1. I followed these installation instructions and then sped through the manual.
  2. Pydev currently supports Eclipse 3.2 to 3.4. It took a while to find an Eclipse download page with version 3.4 but here it is. I installed Eclipse SDK 3.4.2.
  3. Start Eclipse, and click on Help/Software Updates. Add http://pydev.sourceforge.net/updates/ to the list of update sites. Tick the box and click Install to install PyDev.
  4. Following the details at http://www.fabioz.com/pydev/manual_101_interpreter.html, I added a Python interpreter (Name="Python 2.5", Executable="C:\Python25\python.exe").
  5. Installing pylint on Windows is a pain, so I used easy install:
    C:\Python25\Scripts\easy_install.exe pylint
    In the PyLint configuration, you need to specify the location of lint.py. Mine was at C:\Python25\Lib\site-packages\pylint-0.18.0-py2.5.egg\pylint\lint.py.

No comments: