
Integrated Development Environments (IDEs)
The Python interpreter contains everything that is needed to execute a Python script or to test Python code by interacting with the Python interpreter. However, writing scripts requires a text editor. There are usually at least two simple text editors included on a Windows machine (Notepad and Wordpad) and they work in an emergency to edit a script or even write a whole script. Unfortunately, they are very simple and do not allow the user functionality that would make it easier to write multiple scripts or very long scripts.
To bridge the gap, a series of programs collectively known as Integrated Development Environments have been developed. IDEs exist for all programming languages, and include functions such as variable listing, code assist, and more, that make them ideal to craft programming scripts. We will review a few of them to assess their usefulness to write Python scripts. The three discussed as follows are all free and well-established within different Python communities.
IDLE
Python includes an IDE when it is installed. The IDE is called IDLE, which is a word play on both IDE and the name of a prominent member of Monty Python, Eric Idle. It can be started in Windows 7 by going to the Start menu and finding the ArcGIS folder within the Programs menu. Within the Python
folder, IDLE will be one of the choices within that folder. Select it to start IDLE.

IDLE contains an interactive interpreter (i.e. the triple chevron) and the ability to run complete Python scripts. It is also written using Python's built-in GUI module, called Tkinter, so it has the advantage of being written in the same language that it executes.
Another advantage of using IDLE over the Python console (python.exe
) is that any print statements or other script output is directed to the IDLE interactive window, which does not disappear after executing the script. IDLE is also lightweight with respect to memory use. Scripts are opened using a file dialogue contained within the File menu, and recently run scripts are listed within the File menu's, Recent Files.
Disadvantages of IDLE include a limited code assist (or code auto-complete), a useful IDE tool, and having no way to organize scripts into logical projects. There is no way to find all variables contained within a script, another useful feature of other IDEs. Also, the Recent Files menu has a limit on the number of scripts that it will list, making it harder to find a script that has not been run in months (which is a common occurrence, believe me!). IDLE is a passable IDE that is useful if no other programs can be installed on the machine. It is also very useful for rapid testing of code snippets. While it is not my main IDE, I find myself using IDLE almost daily.
PythonWin
PythonWin (short for Python for Windows) is available at http://sourceforge.net/projects/pywin32/files/pywin32, and includes both an IDE and helpful modules to use Python in a Windows environment. Select the newest build of PythonWin, and then select the correct version 32 module based on the installed version of Python (for my machine, I selected pywin32-218.win32-py2.7.exe
, the correct version for my 32-bit Python 2.7 installation). Run the executable, and if the correct version has been downloaded, the installation GUI will recognize Python 2.7 in the system registry and will install itself.
PythonWin includes an Interactive Window where the user can directly interact with the Python interpreter. Scripts can also be opened within PythonWin, and it includes a set of tiling commands in the Windows menu that allows the user to organize the display of all open scripts and the Interactive Window.
Another nice advantage that PythonWin has over IDLE is the ability to display different portions of a script within the same script window. If a script has grown too long, it can be a pain to scroll up and down the script when editing. PythonWin allows the user to pull down from the top of the script to create a second script window, which can focus on a separate part of the script. Also, on the left side, another window can be opened that will list Python classes and variables, making it easier to navigate to a particular section of the script.

One small but helpful feature built into PythonWin's Interactive Window is the ability to search through previously entered code statements. At the triple chevron prompt, hold down the Ctrl key and use the up and down arrow keys to navigate through the lines to find one of interest. This saves a lot of time when testing a particular snippet of code.
All in all, PythonWin is a useful and easy-to-use IDE, and most ArcGIS professionals who create Python scripts use PythonWin. The drawbacks I find with PythonWin include its lack of ability to organize scripts into projects, and its lack of a list of variables that exist within the script, which can be very helpful when navigating larger scripts.
Aptana Studio 3
Sometimes the tools of the greater programming community can seem daunting to new scripters, who are more focused on simply creating a script that will save time on a GIS analysis than using the correct tool for programming daily. It reminds me of inexperienced computer users, who don't feel like they need the full power of a top-of-the-line computer because they only want to browse the internet and send e-mails.
However, the exact opposite is true: the computer adverse is better off having an easier to use top-of-the-line computer, while an experienced computer user could make do with a net book.
The same can be said for programmers and scripters. Sometimes, it's better to have an over-the-top IDE that will actually make a scripter more productive, while an experienced programmer could make do with Notepad. All of the bells and whistles included in an IDE such as Aptana Studio 3 will save scripters time and take remarkably little time to learn.
Aptana Studio 3 is available at http://aptana.com. Download and run the installer provided to install it. Choose a default main project folder that can contain all of the scripts projects; for this book, I created a folder called C:\Projects
. For each project created, Aptana will create a project file holding information about each project. When using Aptana Studio at work, using a network folder can be useful as others can then access the projects with their respective Aptana installations.
Once it has been installed, the next step is to create a PyDev
project. Go to the File menu and select New, and then select PyDev project. When creating this first project, Python Interpreter will have to be added to Aptana's Python path. Aptana can support more than one interpreter; for our purposes, one will do. Go to the bottom of the PyDev project menu and click on Click here to configure an interpreter. When the Preferences/Python Interpreters menu appears, make sure to select Interpreter-Python on the left, and then click on New in the top-right menu.

Once New has been selected, a small dialog will appear asking for a name for the interpreter and the path to the executable. Click on browse and navigate to the folder with python.exe
. No terminal window will be generated when running a Python script using Aptana Studio as all output is redirected to the Aptana Studio console. Select python.exe
and click on OK. Next, click on OK in the Select Interpreter menu, and then click on OK in the Preferences menu. Back in the PyDev Project menu, give the project a name, and either use the default workspace location or a custom one (for example, C:\Projects
).
All of this configuration only has to happen the first time; once that is done, creating a PyDev project will only require giving a name and location. Now, all of the scripts associated with that project will always be listed in the left menu (PyDev Package Explorer), which is a very powerful way to organize projects and scripts.
Making sure that Aptana Studio is in the PyDev perspective (in the Windows/Open Perspective/Other menu, choose PyDev) will give three main windows–Package Explorer on the left, Script window in the middle, and Outline window on the right, where variables contained within a script are listed. Clicking on one of the variables on the right will move the script window to that section of the code, making script navigation fast. Also, I like to add the Console window in the middle below the Script window, where the output of the script can be displayed.
Open scripts each have a tab within the Script window, making it easy to switch between the scripts. Also, the windows can be closed to give more room to the Script window as needed. Hovering over a variable within a script will call up a pop-up menu that describes where the variable was first created, which can be a lifesaver as it is easy to forget at times which variable is which (unless, of course, they are clearly named according to the rules described in the previous chapter; even then, it can be a pain at times).
IDE summary
There are many other IDEs, both commercial and free, available for coding in Python. In the end, each GIS analyst must choose the tool that makes them feel productive and comfortable. This may change as programming becomes a bigger part of their daily work flow. Be sure to test out a few different IDEs to find one that is easy to use and intuitive.