1

I've been trying to teach myself Python scripting for ArcGIS and have gotten frustrated on multiple occasions when I try to debug my script endlessly, only to later find out that it actually works properly when it is loaded into the Python shell in ArcGIS. In the past I have received a variety of errors when running the script in PythonWin, only to have the code work just fine when loaded into ArcGIS.

Why is there a discrepancy between the results of a script run in PythonWin and the Python shell in ArcGIS?

I am using:

  • Windows 8.1
  • Python 2.7.2
  • PythonWin (pywin 32 build 214)
  • ArcGIS 10.1 Advanced

The script is as follows:

#    Import arcpy, env
import arcpy
from arcpy import env

##   Enable file overwrite
env.overwriteOuput = True

#   Set workspace
env.workspace = "c:/documents/arcgis/arcgis tutorials/psu tutorials/lesson3practiceexercisea/washington.gdb"

#   Create new layer feature classes: Cities, ParkAndRide
try:
    arcpy.MakeFeatureLayer_management("CityBoundaries", "CityBoundariesLayer")
    arcpy.MakeFeatureLayer_management("ParkAndRide", "ParkAndRideLayer")
except:
    print "Could not make new layer."

I initially did not post the code because I've had this issue before with code of various types and I was thinking this was not a code error. This code works when loaded the the Python console in ArcGIS, but now when run from PythonWin.

closed as unclear what you're asking by Jason Scheirer, Get Spatial, Fezter, whuber Nov 19 '13 at 23:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Can you post the script in question? Without that it's going to be hard to see what's wrong. – blah238 Nov 19 '13 at 22:14
  • 1
    Do you have the 64-bit Geoprocessing Background Processing option installed? When you install 64-bit Python along with 32-bit, it can do odd things. – MLowry Nov 19 '13 at 22:20
  • 1
    You're being too vague in your question. Please edit it with specific examples. – Jason Scheirer Nov 19 '13 at 22:31
  • 3
    Much better. Could you also include your error message? And see if changing env.overwriteOuput to env.overwriteOutput (typo) fixes it. – Jason Scheirer Nov 20 '13 at 1:44
  • 4
    Exit code 0 means there was no error. Assuming you get that after removing the try/except, then everything is working fine. The "problem" is that you aren't doing anything that has any visible effect (Make Feature Layer creates a temporary layer that only exists within the current Python session). The comment "Create new layer feature classes" suggests a common misunderstanding of the purpose of feature layers and feature classes. See this question for clarification: What's the difference between feature class and feature layer? – blah238 Nov 20 '13 at 2:36

Browse other questions tagged or ask your own question.