Trying to figure out how to create self executing python scripts with using the ArcGIS python window. I'm ok (generally) when developing and running scripts inside the python ArcGIS windows but unable to figure out self executing scripts.

For example ....here is a really simple script created to run a "Select Case" to change annotate attributes in one field (BBB) based upon attributes in field AAA. Goal is simply to double click the *.py file and have it run - outside of ArcGIS

# Import arcpy module
import arcpy

# Import env from arcpy as ENV and set the workspace environment
from arcpy import env
env.workspace = "C:/Users/Jeff Reichman/Documents/My GIS Projects/OpenStreetMap/OSM.gdb"

# Local variables:
Input_Field = "C:/Users/Jeff Reichman/Documents/My GIS Projects/OpenStreetMap/OSM.gdb/SaintLouis/SaintLouis_osm_ln"

# Process: Calculate Field
arcpy.CalculateField_management(Input_Field, "BBB", "x", "VB", "dim x as long/nselect case [AAA]/n  case 1: x = 100/n  case 2: x = 200/n  case 3: x = 300/n  case 4: x = 400/n  case 5: x = 500/n  case else: x = -999999/nend select")
  • 1
    It sounds like you are trying to figure out how to run python scripts outside of ArcGIS. What happens when you double click on a .py file (say, in Windows explorer) currently? Dec 19, 2014 at 2:57

1 Answer 1


I think your question is pure Python rather than GIS but I put together a simple Python script called test.py below to prove that it can be easily done.

import arcpy


I placed test.py in C:\temp and used Windows Explorer to double-click it.

A DOS window appeared for about 10-15 seconds, and then closed. Half a second later Windows Explorer refreshed itself to show the expected shapefile (C:\temp\test.shp) had been created.

As @NathanW and @MichaelMiles-Stimson have commented, if this does not "just work":

  1. Check your file association for *.py
  2. Think about whether your Python script will find any required ArcGIS licensing available

This was running on a machine that has a Single Use license always available. Installing ArcGIS 10.2.2 for Desktop months ago installed Python and appears to have set the correct file association as part of that process.

  • 2
    The main thing is making sure Python is set to run .py files. thewindowsclub.com/change-file-associations-windows
    – Nathan W
    Dec 19, 2014 at 3:16
  • 1
    That and you must address your licensing... when running inside ArcGis you know you've got a license but running from cmd or double click it's not guaranteed. I suggest you put a try/except around your import arcpy to detect failure. python itself will run just fine until you hit the first Esri command and then fall flat if it can't get a license. See help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… Dec 19, 2014 at 3:18
  • @NathanW In my case, on Windows 7, I think installing the Python that comes as part of ArcGIS 10.2.2 for Desktop, must have set up the file association because it "just worked".
    – PolyGeo
    Dec 19, 2014 at 3:19
  • @PolyGeo yeah normally it will set it. Sometimes it's not though so it's easy to check.
    – Nathan W
    Dec 19, 2014 at 3:23
  • Thank you for the tips; it was the licensing issue. It's always something "simple." :)
    – Jeff
    Dec 19, 2014 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.