Monday, October 21, 2013

PyScripter for ArcGIS 10.2

This tutorial is for my GEOG 490 students. I hope others find use in it too.


PyScripter is another Python GUI (Graphical User Interface) similar to the ones we've been using in class (IDLE and PythonWin). PyScripter has several advantages over these other programs, mainly the ability to auto-complete ArcPy, which really speeds things up.


Installing PyScripter

It's important to start out with a clean install of Python. I tried to install PyScripter with multiple versions of Python on my office computer and the result was a frustrating hour trying (and failing) to get PyScripter to talk to ArcPy. If you need multiple versions of Python, I wish you luck. Please let me know if there's a secret I missed.

If you have only installed ArcGIS 10.2 (Python 2.7.3 comes as part of that installation) you can skip the first step.

  1. Uninstall all versions of Python from your computer. You will then need to repair your ArcGIS 10.2 installation to reinstall the ArcGIS-flavored Python.
  2. Download PyScripter (http://code.google.com/p/pyscripter/http://sourceforge.net/projects/pyscripter/
    1. Either version (32-bit or 64-bit) should work on most machines. If you're unsure which version you need, go with the x86 version.
    2. There is a stand alone version of PyScripter that you can install on a flash drive or external hard drive. To get that version talking to ArcPy visit Map Guy Mike's tutorial
  3. After the install check the Python paths for ArcPy
    1. Navigate to c:\python27\Lib\site-packages
    2. Find the Desktop10.2.pth file-you'll need to view/edit this file with Notepad
    3. This file should contain the right information, feel free to skip this step and come back to it if ArcPy doesn't work.
    4. There should be three line in the file:
      c:\Program Files\ArcGIS\Desktop10.2\arcpy
      c:\Program Files\ArcGIS\Desktop10.2\bin
      c:\Program Files\ArcGIS\Desktop10.2\ArcToolbox\Scripts
    5. If you need to, add these lines, save and close the file. If these lines are in there, you are good to go.
  4.  Fire up PyScripter (in the Start menu, choose PyScripter (Latest Python Version))

PyScripter Setup

Only one small thing to do here...Go to the Tools menu, then Options > IDE Options. Under special packages add arcpy to the end of the list.


Test it out

In the bottom Interpreter (command line) window try import arcpy  hit enter (maybe twice) and see if it works.

A Quick Tour

The upper window in PyScripter is the Editor window-this is where you will write your stand alone code. The auto-complete works in here as long as you have your module import statements at the top (which you should anyway).
** As a bonus, you don't have to save your scripts before you run them. BUT, be sure that you do save them at some point.

The bottom window is the Interpreter (command line) window. This is like the main IDLE window, where you can test individual code bits and where some messages will appear.

Along the bottom are some tabs for advanced code editing and debugging. One of my favorites is the Variables tab. This is where you can see what variables are in memory and what their values are. This will be important as we start to build larger scripts and need to start debugging them.


.

2 comments: