Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
>>> import arcpy
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\arcpy\__init__.py", line 21, in <module>
    from arcpy.geoprocessing import gp
  File "C:\Python27\lib\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from _base import *
  File "C:\Python27\lib\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting
ImportError: DLL load failed: The specified module could not be found.

This is the error I get when i try to import arcpy. Any suggestions?

share|improve this question
    
What IDE are you using? –  Aaron Mar 26 '13 at 19:55

3 Answers 3

In Arcmap open the python a.k.a. command line window, under Geoprocessing in 10.1, type import os, and then os.__file__ to deduce the location of python.exe (recipe found here). Use the results of that to fine tune the PYTHONPATH environment variable in whatever command shell or IDE you're using.

>>> import os
>>> os.__file__
'C:\\Python27\\ArcGIS10.1\\Lib\\os.pyc'

so python.exe, and thus PYTHONHOME is one level up, C:\Python27\ArcGIS10.1.

Here's my batch file to enable ArcGIS python in a standard Windows Command Prompt shell:

@echo off
echo.
echo.   Setting environment for ArcGIS python 2.7
echo.
set PYTHONHOME=C:\Python27\ArcGIS10.1
set PYTHONPATH=%PYTHONHOME%;%PYTHONHOME%\Lib;%PYTHONHOME%\DLLs
set PATH=%PYTHONHOME%;%PYTHONHOME%\Scripts;%path%
set py
python --version
share|improve this answer

i'm not sure why your arcpy has been copied to c:\python27\lib. The standard install location is inside ArcGIS\desktop10.x or equivalent for other products.

approach to fix #1 : dodge stray arcpy package. if there is a arcpy folder in the product install directory (eg. c:\Program Files (x86)\ArcGIS\Desktop10.x.) it could just be hitting this stray arcpy folder first. You can rename c:\python27\lib\arcpy to c:\python27\lib\arcpy2 then import arcpy will miss this stray and (hopefully) hit the real arcpy package

approach to fix #2 : make stray arcpy package find arcgisscripting. The error is "can't find arcgisscripting" which is a pyd file inside the arcgis "bin" folder.

Easiest way to add it is to create a text file called something.pth inside c:\python27\lib\site-packages

into this file, put 2 paths C:\Program files (x86)\desktop10.2\bin C:\Program files (x86)\desktop10.2\ArcToolbox\Scripts

the second path certain gp tools rely on (inside the Spatial Stats library).

share|improve this answer
    
The above copy/paste was from PythonWIN. I reinstalled Python into my ArcGIS directory. I followed your approach #2, opened PythonIDLE and this is the message I get now. –  Maksim Mar 26 '13 at 20:13
    
>>> import arcpy Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import arcpy ImportError: No module named arcpy –  Maksim Mar 26 '13 at 20:14
    
ok, you do have some arcgis product installed (yes?) and in product install dir there is a folder named 'arcpy' yes? if yes, then create a .pth as per approach #2 above, and set 3 paths in it #1 path to arcgis\bin, #2 path to arcgis\arcpy #3 path to arcgis\arctoolbox\scripts –  gotchula Mar 26 '13 at 20:26
    
Also see gis.stackexchange.com/questions/27058/… –  matt wilkie Mar 26 '13 at 20:31

It's better to check the GIS wiki to help you in this case. In different versions of ArcGIS we need to use different modules. From the wiki:

Python support in different versions of ArcGIS

The geoprocessor python object is accessed differently depending on the version of ArcGIS: [edit] ArcGIS 9.0/9.1

These versions of ArcGIS use Python 2.1 with the PythonWin[6] package to access a >Geoprocessor using a COM interface:

import win32com # PythonWin gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

The GpDispatch COM interface is available in later versions of ArcGIS, though it is only >available to Python if PythonWin is installed. [7] GpDispatch provides access to >geoprocessing using any language that supports COM. [edit] ArcGIS 9.2

This version of ArcGIS uses Python 2.4 and brought a major change to how the Geoprocessor >was created. The win32com.client is no longer needed, replaced by the Python-native >(non-COM) arcgisscripting module. This both provides better performance and allows >platform independence; Python geoprocessing scripts using the arcgisscripting module are >supported on non-Windows versions of ArcGIS Server.

import arcgisscripting gp = arcgisscripting.create()

[edit] ArcGIS 9.3/9.3.1

These versions of ArcGIS use Python 2.5.1 and can be used with both the 9.3 version of >arcgisscripting or the original 9.2 version of arcgisscripting.

import arcgisscripting gp = arcgisscripting.create() # 9.2 (default for ArcGIS 9.2,9.3) gp = arcgisscripting.create(9.3) # 9.3

You can determine the version of the geoprocessor from its ScriptVersion property:

print "GP version: " + str(gp.ScriptVersion)

[edit] ArcGIS 10

This version of ArcGIS adds the new arcpy module. ArcPy is a site-package that builds on (and is a successor to) the arcgisscripting module. Its goal is to create the corner-stone for a useful and productive way to perform data analysis, data conversion, data management, and map automation with Python.

import arcpy

The older versions of the geoprocessor (GpDispatch and the arcgisscripting module) are still supported to allow for forward compatibility of Python scripts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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