Import ArcPy

ArcPy is a Python site package that provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python. ArcGIS applications and scripts written using ArcPy can access and work with the numerous Python modules developed by GIS professionals and programmers from many disciplines.

# Import arcpy
import arcpy

# Set the workspace environment and run Clip
arcpy.env.workspace = 'C:/Data/Tongass'
arcpy.analysis.Clip('standb4', 'clipcov', 'standby_clip', 1.25)

Once you import ArcPy, you can run all the geoprocessing tools that are in the standard toolboxes installed with ArcGIS.

Python also has many other core and third-party modules. To work with the os and sys modules, you can use the same import syntax:

# Import arcpy, os and sys
import arcpy
import os
import sys

Environment variables

When you import the ArcPy package, the following packages are also imported by default:

  • datetime
  • math
  • numpy
  • sys
  • time

This behavior may conflict with expectations. To restrict the import of these additional packages, set the ARCPY_NO_IMPORTS system environment to any value.

Set the ARCPY_NO_IMPORTS environment variable before importing arcpy in a script.

import os
os.environ["ARCPY_NO_IMPORTS"] = "1"

import arcpy

The ARCPY_NO_IMPORTS environment variable is only applicable in a stand-alone script; it does not affect behavior within the ArcGIS Pro application.

Related topics

In this topic
  1. Environment variables