Thursday 16 July 2015

arcgis 10.0 - import arcpy yields "TypeError: This object does not support enumeration"


Similar to Enumeration Problem with Eclipse and arcgisscripting?, with Arcgis v10 I no longer seem to be able to run python scripts from a command shell. Entering the same code into an interactive python console from the same shell does work! Other scripts I have from a few months ago seem to work fine. I don't get it.


This works:


d:\s>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy
>>> arcpy.env.workspace = 'd:/'
>>> print arcpy.env.workspace
d:/
>>>

Create a minimal test file:


d:\s>copy con d:\code\arcgis\test-arcpy.py
import arcpy

arcpy.env.workspace = 'd:/'
print "Workspace is: ", arcpy.env.workspace^Z
1 file(s) copied.

and give it a spin:


d:\s>python d:\code\arcgis\test-arcpy.py
Traceback (most recent call last):
File "d:\code\arcgis\test-arcpy.py", line 1, in
import arcpy
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in

from geoprocessing import gp
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in
from _base import *
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 568, in
env = GPEnvironments(gp)
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 565, in GPEnvironments
return GPEnvironment(geoprocessor)
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 521, in __init__
self._refresh()
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 523, in _refresh

envset = (set(env for env in self._gp.listEnvironments()))
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 523, in
envset = (set(env for env in self._gp.listEnvironments()))
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 246, in __getitem__
raise TypeError("This object does not support enumeration")
TypeError: This object does not support enumeration

update it's directory specific! If I copy that same test-arcpy.py file somewhere else it works.



Answer



Aahhhh, found it! I ran afoul of keeping scripts I wrote for Arcgis 9 and 10 in the same directory. Something about the initialization logic in import arcpy finds the custom arcgisscripting.py used for running python 2.6 with arcgis 9.3 when they are located together.



So as long as I keep them separated all is copacetic. I didn't run into this earlier because my other v10 scripts are part of a v10 specific project stored in a different spot.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...