I would want to use arcpy in my python code. I am able to import it through the ARCGIS desktop python console. But I am not able to import it into Python IDLE. I get the following error
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 246, in
__getitem__raise TypeError("This object does not support enumeration")
I mentioned the following folders as a part of my python path.
C:\Program Files\ArcGIS\Desktop10.0\arcpy;
C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy;
C:\Python26\ArcGIS10.0\Tools\Scripts
I found the same issue being mentioned.
import arcpy yields "TypeError: This object does not support enumeration"
The user says it is due to the following:
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.
I have only ARCGIS 10 and i am not aware of how arcpy looks up for its modules.
-
Are you simply typing import arcpy into the Python shell (of IDLE) to see this error? Or perhaps simply typing import arcpy into a Python window (of IDLE) and using Run Module to see it? Do you have to use a long PYTHONPATH? I just have PYTHONPATH=C:\Python26 and C:\Python26\ArcGIS10.0 as part of my PATH variable.PolyGeo– PolyGeo ♦2012年06月08日 05:43:10 +00:00Commented Jun 8, 2012 at 5:43
-
yes, im just importing the module in the IDLE window.I also tried using this python interpreter in ARCGIS,imported the arpy modules. I still get the error.Karthik Bharadwaj– Karthik Bharadwaj2012年06月08日 05:56:27 +00:00Commented Jun 8, 2012 at 5:56
-
1Do you have to use a long PYTHONPATH? I just have PYTHONPATH=C:\Python26 and C:\Python26\ArcGIS10.0 as part of my PATH variable.PolyGeo– PolyGeo ♦2012年06月08日 06:39:20 +00:00Commented Jun 8, 2012 at 6:39
-
1windows solution -> reinstall both arcgis and python.urcm– urcm2012年06月08日 06:59:14 +00:00Commented Jun 8, 2012 at 6:59
-
1I would like to understand how the underlying issue and how it is caused, at the worst case i think il have to uninstsall both. @PolyGeo. I changed my path and python path variable. but the issue removes the same.Karthik Bharadwaj– Karthik Bharadwaj2012年06月08日 07:06:01 +00:00Commented Jun 8, 2012 at 7:06
1 Answer 1
Fix your PYTHONPATH
. From ArcGIS help:
When using an import statement, Python looks for a module matching that name in the following locations (and in the following order):
- Paths specified in the
PYTHONPATH
system environment variable - A set of standard Python folders (the current folder,
C:\python2x\lib
,C:\python2x\Lib\site-packages
, and so on) - Paths specified inside any
.pth
file found in 1 and 2
For more information on this, see the following: http://docs.python.org/install/index.html#modifying-python-s-search-path.
The installation of ArcGIS 10.0 products will install Python 2.6 if it isn't already installed. The installation will also add the file Desktop10.pth
(or Engine10.pth
or Server10.pth
) into python26\Lib\site-packages
. The contents of this file are two lines containing the path to your system's ArcGIS installation's arcpy and bin folders. These two paths are required to import ArcPy successfully in Python version 2.6.
When using an import statement, Python refers to your system's PYTHONPATH
environment variable to locate module files. This variable is set to a list of directories.
Tip:
If importing ArcPy produces either of the following errors, the required modules could not be found:
ImportError: No module named arcpy
ImportError: No module named arcgisscripting
To address this, browse using Windows Explorer to the python26\Lib\site-packages
folder and add or edit the Desktop10.pth
file. The file should contain the two lines shown below (corrected to your system's path if they do not match):
C:\Program Files\ArcGIS\Desktop10.0\arcpy
C:\Program Files\ArcGIS\Desktop10.0\bin
-
Thanks all. Like @Aragon suggested I re-installed both ARCGIS Desktop and Python. put the Desktop.pth file in place and it worked.Karthik Bharadwaj– Karthik Bharadwaj2012年06月11日 10:12:00 +00:00Commented Jun 11, 2012 at 10:12