PROBLEM
The ArcPy module is used in ArcGIS functionality and as a stand-alone script. In some cases, importing the ArcPy module fails while in others, import is successful, but the functions within the module are unavailable, and the script fails to perform a desired process, such as running a geoprocessing tool. In addition, when attempting to import ArcPy using 64-bit Python with ArcGIS Server, the following error message is returned:
Error: "ImportError: No module named arcpy"
To access the Python interpreter and run Python scripts, the location of the required python.exe file must be known to the system. For the system to recognize the location, the path to the python.exe file is included in Windows Environment Variables. The path to the location is named PYTHONPATH.
The path defined in Environment Variables follows the latest installation of Python by default. So, if Python 3.7 is installed after Python 2.7, the path to the python.exe file version 3.7 is specified in Environment Variables. This causes Python processes running in ArcGIS Desktop to fail.
If importing the module fails, this may be due to:
Note: Users can install different versions or bit versions of Python. ArcMap uses Python 2.7.x (32-bit), ArcGIS Server uses Python 2.7.x (64-bit), and ArcGIS Pro uses Python 3.x. For more information, refer to the following article, FAQ: What version of Python is used in ArcGIS? Using a version of Python other than the version expected with ArcGIS can lead to compatibility issues.
If importing the arcpy module is successful, but the functions are unavailable, check the location of the module. Each module in the arcpy library has a unique name and resides in the folder where Python is installed. Below are common locations of the arcpy module:
C:\Program Files (x86)\ArcGIS\Desktop10.6\arcpy\arcpy
C:\Program Files\ArcGIS\Server\arcpy\arcpy
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib
When running a Python script, the script first locates the matching module in the folder containing the script, and then imports the script. On the other hand, if there is a script named arcpy.py residing in a closer location such as in Desktop, the Python script grabs the one in Desktop instead.
If importing the arcpy module fails, edit or add the Python path in the Windows Environment Variables. The correct path for the Python installation is as follows:
C:\Python27\ArcGIS10.x
C:\python27\ArcGISx6410.x
C:\Program Files\ArcGIS\Pro\bin\Python
The following steps describe how to add the Python path to Environment Variables.
Note: For ArcGIS Desktop, open the Desktop10.x.pth file in the C:\Python27\ArcGIS10.x\Lib\site-packages folder using a text editor, for example, Notepad++, and check if the file contains the following three paths: C:\Program Files (x86)\ArcGIS\Desktop10.x\bin C:\Program Files (x86)\ArcGIS\Desktop10.x\arcpy C:\Program Files (x86)\ArcGIS\Desktop10.x\ArcToolbox\Scripts
Note: For ArcGIS Pro, open the ArcGISPro.pth file in the C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages using a text editor and check if the file contains the following syntax: import os; d = r"C:\Program Files\ArcGIS\Pro\bin"; os.environ["PATH"] = r"{};{}".format(d, os.environ["PATH"]) import sys; d = r"C:\Program Files\ArcGIS\Pro\bin"; sys.path.append(d) import sys; d = r"C:\Program Files\ArcGIS\Pro\Resources\ArcPy"; sys.path.append(d) import sys; d = r"C:\Program Files\ArcGIS\Pro\Resources\ArcToolbox\Scripts"; sys.path.append(d) import os; e = "FOR_DISABLE_CONSOLE_CTRL_HANDLER"; os.environ[e] = '1' if (not e in os.environ) else ""
Note: For ArcGIS Server, open the Server10.x.pth file in C:\Python27\ArcGIS10.x\Lib\site-packages using a text editor and check if the file contains the following three paths: C:\Program Files\ArcGIS\Server\arcpy C:\Program Files\ArcGIS\Server\bin C:\Program Files\ArcGIS\Server\ArcToolbox\ScriptsIf an incomplete or a corrupted installation is suspected, repair the software.
conda create -n EnviornmentName
conda install -c esri ArcGIS
conda install -c esri arcpy
Get help from ArcGIS experts
Download the Esri Support App