I want to use some arcpy function outside arc map i used following code but it ends up with error no module named arcpy can anyone help

import sys
sys.path.append("D:\Installed Softares\ArcGIS\Desktop10.1\arcpy");
import sys.arcpy
Radiancetemp = "C:\\Model_Uz\\radianMap"
# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("Float(\"%LE71970282002228EDC00_B6_clip.TIF %\" * 0.03705882) + 3.2", Radiancetemp)

Instead of import sys.arcpy, try import arcpy

| improve this answer | |

Here is an example of a SA script that I run from the command line:

import os,sys,arcpy

if (len(sys.argv) != 3):
    arcpy.AddError("Incorrect number of parameters") # this script has 3 parameters

if arcpy.CheckExtension("Spatial") == "Available":
    arcpy.AddMessage("Checking out Spatial")
    arcpy.AddError("Unable to get spatial analyst extension")
# do some stuff, not important in this context
arcpy.CheckInExtension("Spatial") # release spatial analyst extension

This shows how to import arcpy and get the spatial analyst license to perform arcpy.sa geoprocessing. In ArcMap/ArcCatalog the extensions are already checked out, when you're running in command they are not so you have to do that in the script. When you import arcpy the Esri license (as set up in the Desktop Administrator) is checked out and is released when the script terminates.

| improve this answer | |

Double check that the directories that python needs are in the PYTHONPATH environmental variable. The paths that I have are: C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy;C:\Program Files (x86)\ArcGIS\Desktop10.2\bin\

| improve this answer | |
  • 1
    PYTHONPATH isn't really necessary (resources.arcgis.com/en/help/main/10.2/index.html#//…) as python searches A set of standard Python folders (the current folder, c:\python2x\lib, c:\python2x\Lib\site-packages, and so on) then Paths specified inside any .pth file found in 1 and 2 to load the modules. This should be reflected in you sys.path (i.e. print(sys.path) ) I would only implement the PYTHONPATH environment variable if there were problems, like with a second python install. – Michael Stimson Mar 23 '15 at 0:56
  • 1
    I had the same error as above and adding the path to arcpy resolved it. It may not be necessary for every situation, but inaccessibility to the arcpy module will give that error and adding the path to the the module can fix it. – akthor Mar 23 '15 at 1:09
  • 1
    Like I said, I wouldn't set it unless there is a problem, perhaps you could extend your answer and say 'it might help if you set a system environment variable and put these values in it, it worked for me in a similar situation' or the user might be frantically searching for a variable that isn't set by default. – Michael Stimson Mar 23 '15 at 2:11

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