Python is a free, cross-platform, open-source programming language that is both powerful and easy to learn. It is widely used and supported. To learn more about Python, visit python.org.
Python was introduced to the ArcGIS community with ArcGIS 9.0. Since then, it has been accepted as the scripting language of choice for geoprocessing users and continues to grow. Each release has furthered the Python experience, providing you with more capabilities and a richer, more Python-friendly experience.
Esri has fully embraced Python for ArcGIS and sees Python as the language that fulfills the needs of the Esri user community. Here are some of the advantages of Python:
- Easy to learn and excellent for beginners, yet superb for experts
- Highly scalable, suitable for large projects or small one-off programs known as scripts
- Portable, cross-platform
- Embeddable (making ArcGIS scriptable)
- Stable and mature
- A large user community
If you are migrating Python code written against a version of ArcGIS Desktop (or ArcGIS Server or ArcGIS Engine), see Python migration for ArcGIS Pro. The primary differences are that ArcGIS Pro uses Python 3 and other ArcGIS products use Python 2, and ArcPy has some differences in the tools it includes; for example, the arcpy.mapping module is replaced by the arcpy.mp module.
A suitable Python reference book is strongly recommended to augment the ArcPy-focused information you find here. For Python beginners, "Learning Python" by Mark Lutz and David Ascher, published by O’Reilly & Associates, and "Core Python Programming" by Wesley J. Chun, published by Prentice Hall, are both good introductions to the language and are not overwhelming in scope. There are many other books on Python and its uses, with new ones being released regularly, so explore what is available. The Python website has full documentation for Python, but it is concise and developer oriented. There is a large online Python community with many online resources that are accessible from the Python home page.
If you are new to Python, the external tutorials listed here are recommended for you.
Python tutorials for programmers
The external tutorials listed here are aimed at those who have experience with other programming languages (Perl, Visual Basic, C).
Python is the primary language for automation in both ArcGIS 10.x and ArcGIS Pro, due in large part to its versatility and extensibility. It is partially due to these virtues that Python is also becoming one of the most widely used programming languages in general. Python has a rich ecosystem of preexisting packages that can be leveraged in ArcGIS, but managing which packages are installed on a system can be a complex and time-consuming task, especially when working on multiple projects or trying to share code with others.
To leverage this versatility, the Python community has created methods to easily create projects in multiple versions of Python and simplify the process of installing nearly all publicly available Python packages. Conda is the most popular and widely used Python package manager.
Integrating the functionality of conda into ArcGIS Pro will remove many hurdles faced when writing Python code. It will support installing open-source and third-party libraries that are associated with an individual project, rather than into the base Python installation. This will simplify the process of sharing complex Python tools that will work on multiple computers. Conda does this by providing environments that both isolate installations and solve dependencies.
The subsection below describe how to run Python outside of the ArcGIS Pro app.
From a command prompt
To start Python from a command prompt, type the following:
All paths shown assume a per machine (all users) installation of ArcGIS Pro. If ArcGIS Pro has been installed for the current user, substitute %LOCALAPPDATA% for %PROGRAMFILES%.
To run a Python script from a command prompt (arguments can be added following the .py file), type the following:
"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy" myscript.py
Start the ArcGIS Pro Python 3 conda environment:
From a batch file
To run a Python script from a .bat file, use call on propy:
@echo Run my Python script call "%PROGRAMFILES%\ArcGIS\Pro\bin\Python\Scripts\propy" myscript.py @echo Finished
As a scheduled task
If you are running a Python script as a scheduled task, the program or script should be C:\PROGRA~1\ArcGIS\Pro\bin\Python\Scripts\propy, and the arguments should include the full path to your Python script.
The following shortcuts can be used to access Python:
Python Command Prompt
Opens a command prompt window initialized with the current conda environment. To start an interactive Python session, type python. To run a Python script, type python, followed by the path of a .py file.
Python Interactive Terminal
Opens a Python session with the current conda environment.
Most modern Python integrated development environments (IDE) can be used seamlessly with conda by configuring the version of Python that the IDE uses. The primary step involves directing the IDE to use the correct Python.exe within the ArcGIS Pro installation. To configure several common IDEs, see How to set up an IDE or the documentation for the particular IDE.
Python IDLE can be launched from a conda environment by typing idle.
ArcPy must be run from inside the conda environment, which ArcGIS Pro uses to manage the installation of Python. You can access this environment by launching Python from the links in the ArcGIS > ArcGIS Pro start menu group or by running proenv in a terminal.
If a conda environment is opened in a command window without the necessary administration privileges, a message will appear indicating the lack of permissions. Close the command window, reopen it, and Run as administrator.
Authorizing Python outside the application
If you run Python scripts that use ArcGIS Pro functionality outside of the ArcGIS Pro application, such as a Python IDE, from a command prompt, or running scripts through scheduled tasks, one of the following conditions must be true:
- Sign me in automatically is checked when signing in to ArcGIS Pro.
- ArcGIS Pro is currently open.
- ArcGIS Pro has been authorized to work offline.
If one of the above conditions is not met, you will encounter a RuntimeError: NotInitialized exception when importing arcpy or arcgisscripting.
Learn more about licensing ArcGIS Pro.