Pages

Sunday, November 20, 2011

Writing and debugging ArcGIS python scripts with Eclipse or Aptana IDE

 Writing and debugging complex ArcGIS python scripts that interact with other classes and packages can sometimes be a real ordeal if you don't have the right tools. For that reason, sometime ago I decided to try to come up with a way that enables me to  use a complete Software IDE suite such as Eclipse or Aptana. 


1- First step is to get Eclipse IDE
-       Go to Eclipse.org and download Eclipse Classic
-       Unzip downloaded file to a preferred location (C:\Eclipse for instance)
-       Start Eclipse by running Eclipse.exe (You can create a shortcut on your desktop.)
2- Once Eclipse is running you will need to install PyDev plugin for Eclipse. This step is not required for Aptana users (PyDev is pre-installed with it)
-       Go to Help --> Install New Software and then click Add.
-       Add a name and set the location to http://pydev.org/updates
-       Click OK.


3- Select PyDev (PyDev Mylyn Integration is optional) then click on Next.



4- Accept the license agreement then click finish. After installation is completed, restart Eclipse.
5- With Eclipse or Aptana running open the PyDev Perspective. 
  -Click on Open Perspective then select PyDev.


6- Now go to File -> New (or Alt + Shift + N) and Select PyDev Project to create a new Python project.
  - Name the project and click the link to configure the python interpreter.



7- Click on New and Navigate to the Python installation that comes with ArcGIS software (See screenshots below.)






8- Select All folder then click OK to add them to the python path

9- Click Apply and wait for the interpreter to be configured.


10 - After the force built-in is completed, your PyDev Project should show the path to the python executable folder.
   - Right Click the project name and add a new PyDev Package
   - Then add new PyDev Module


11- Import the arcpy library into your python module.
    - From this point, code completion should work for arcpy modules too.


12- Add some code, set a breakpoint, and then Click Run -> Debug As -> Python Run. 
-       Eclipse IDE will ask you to switch to debugging perspective.
-       Click OK
-       At this point you should be able to use all the development and debugging features that come with Eclipse IDE.



2 comments:

  1. Just wanted to thank you for the post. I have not yet fully grasped all that Eclipse can offer and this small configuration opens the door for me to advance my geoprocess scripting to a higher level, faster.

    ReplyDelete