Although Python is installed automatically with each version above ArcGIS Desktop 10, setting up a working python environment for using the ArcPy site package can be a little cumbersome. This blog post offers some help with setting up the right environment and double-check if things work properly.
What is ArcPy and what does it contain?
First introduced in ArcGIS 10, the ArcPy site-package allowed for a closer integration of ArcGIS and Python. ArcPy provides access to geoprocessing tools as well as additional functions, classes, and modules that allow for create simple or complex workflows quickly and easily.
ArcPy is organized in tools, environments, functions, classes, and modules. Writing good code requires knowledge of these entities and Python syntax (its grammar rules so to speak). These concepts are all derived from other programming languages, so learning other programming languages will enhance your understanding of Python automatically too. Although you don´t to know all the details before getting started, they will help you write better code once you get started.
Where can I find ArcPy on my pc to check if it´s there and working properly?
Python is installed automatically with the installation of ArcGIS Desktop since version 10. If you´re curious to see what version goes with each ArcGIS version, see the link below (1). Although site packages are listed in a separate directory (for example in C:\python27\arcgis10.2\lib\site-packages), you won´t find any mention of ArcPy here. Instead, in this directory you will find a file with the .pth extension which tells you where to find the ArcPy site package, namely the program files directory. You can check if ArcPy is functioning properly by moving to the directory where Python was installed with ArcGIS (such as c:\python27\arcgis10.2), open the python.exe file and type “import arcpy”. If there are no error messages, you´re good to go.
If you´re using and IDE such as PythonWin and can´t access ArcPy there, this means that your editor cannot access the right python.exe file, meaning the one that came with the ArcGIS installation. The solution is to manually edit your Environment Variables in the advanced system settings and add the path to your Python installation (for example: C:\Python27\ArcGIS10.2). In PythonWin, you can manually edit the path to the correct Python version under the ‘Tools’ dropdown menu if necessary. It´s discouraged to have multiple versions of Python installed on your computer to avoid the problems mentioned above. This is easier said than done: imagine a machine with both ArcGIS Desktop and ArcGIS Pro installed on it. Both make use of different Python versions (Python 2 and 3).
Using ArcPy and Esri applications
ArcGIS and ArcPy are installed together on the same machine because ArcPy is dependent on ArcGIS software in order to run. This means you cannot use ArcPy if you don´t have any Esri applications installed. Other than ArcGIS Desktop, ArcPy is installed with ArcGIS Server, ArcGIS Pro and ArcEngine, a collection of GIS components and developer resources that is part of the Esri Developer Network (EDN) annual subscription. It also runs on Linux.