Python has a rich ecosystem of pre-existing Python packages that can be leveraged within ArcGIS Pro, but managing which packages are installed on a system can be a complex and time consuming task, especially when working on multiple projects at once or trying to share code with others.
These packages encourage the sharing of user-developed functionality, and are hosted at a variety of locations on the web. While ArcGIS users have always been able to utilize Python packages in their scripts, the workflow of finding, installing, and using these packages has traditionally been time consuming and subject to compatibility issues.
The Python community has designed methods to create projects in multiple versions of Python while trivializing the process of installing nearly all publicly available Python packages. These solutions are commonly referred to as Package Managers.
To ease the usage of Python packages in ArcGIS scripts, ArcGIS Pro integrates a powerful and widely used package management system called conda. Integrating conda with ArcGIS Pro allows you to quickly and easily utilize the functionality in Python's ecosystem of open-source and third-party packages. It takes the guess work and hassle out of installing, running, and updating packages and their dependencies for use in your Python scripts.
To further extend the versatility and utility of Python packages, multiple installations of Python can exist side-by-side on a single workstation, independent of one another. This allows for multiple versions of Python be accessible simultaneously. Each of these installations is referred to as a Python environment.
Each Python environment can have its own set of packages, allowing you to easily switch between different sets of Python functionality without having to uninstall and reinstall packages each time. The information about environments can be shared with others, making it trivial to recreate the exact same environment on additional workstations. To supplement its package management capabilities, conda also functions as an environment manager.
By default, ArcGIS Pro has a single conda environment, arcgispro-py3, which includes all Python libraries used by ArcGIS Pro as well as several others such as scipy and pandas. There are several shortcuts for accessing this environment installed in the including the Python Command Prompt shortcut to open a command prompt initialized with the arcgispro-py3 environment.
Working with Python environments
ArcGIS Pro includes a package manager that allows you to interact directly with conda, without having to leave ArcGIS Pro. To access Python when working in ArcGIS Pro, click the Project tab and click Python to access the Python Package Manager. To create, edit or remove environments click on the Manage Environments button.
As of ArcGIS Pro 2.2, the default arcgispro-py3 environment is read-only and cannot be modified. Changes can be made by creating a new environment (or cloning an environment) into your user profile and making desired changes to the new environment.
When updating from an earlier version of ArcGIS Pro, if an older arcgispro-py3 environment exists, it will be renamed to prevent overwriting. The existing environment's folder name will be appended with _backup. A new default arcgispro-py3 environment will be created and activated automatically.
Creating a new environment
To create a new environment within the Manage Environments dialog, click the New button. This will open the Create New Environment allowing you to set the environment's name. The path cannot be altered, it is for reference only.
The new environment will be a copy of the default arcgispro-py3 environment; only the default packages included with ArcGIS Pro will be installed. New environments are located within your user profile, and you have full permissions on these environments to add, update and remove packages.
Cloning an existing environment
To duplicate an existing environment, use the Manage Environments dialog to select an environment and click the Clone button. This will create an environment with -clone appended to the original environment's name and path. The environment can be renamed using the Edit button.
The cloned environment is an exact copy of the original environment; any newly installed packages or updated package versions present in the original environment will be included in the cloned environment. This functionality can be used to back up an environment before making changes. Cloned environments are located within your AppData directory, and you have full permissions on these environments to add, update and remove packages.
Editing an environment
To rename an existing environment, click the Edit button on the appropriate environment in the Manage Environments dialog. The updated name will also be applied to the environment's folder path. The default arcgispro-py3 environment cannot be renamed.
Removing an environment
To delete an environment, click the Remove button on the appropriate environment. The default arcgispro-py3 environment cannot be removed.
Activating an environment
The active Python environment is used to run any Python commands executed from within the application. To change the active environment in the Manage Environments dialog, select the radio button in the Active column beside the respective environment to be activated. After changing the active environment, ArcGIS Pro must be restarted to reinitialize Python and use the new environment.
Working with Python packages
One of the advantages of using conda, is the availability and ease of installing many 3rd party Python packages into your current environment. Conda will install and manage any additional 3rd party dependencies to ensure that the package can be immediately used. Once the package is installed you can use it freely in the Python window, and within any script tools or Python toolboxes you may have.
Viewing installed packages
To see the currently installed packages click on the Installed Packages button. All 3rd party Python packages installed with ArcGIS Pro and any additional libraries you've already added will be displayed.
Updating outdated packages
Over time, Python packages may become out of date. If there are updates available that you would like to include, click on the Update Packages button to see available updates. You can update a single package by clicking on the package, and clicking the Install button, or you can choose to install all updates by clicking on the Update All button. Some packages are pinned to a specific version and cannot be updated; these particular packages will not appear in the list even when updates are available. Since the default arcgispro-py3 environment is read-only, it's packages cannot be updated. Create or clone an environment to update packages.
Installing available packages
By clicking on the Add Packages button, you can see all available Python packages that are compatible with your Python environment. By default the latest current version of each package is shown, but you can also access earlier versions by clicking on the version number under the Version column. To install a Python package, click its name under the Name column, change the version if needed, and click the Install button. Since the default environment is read-only, it cannot be updated with new packages. Create or clone an environment to install packages.
Removing installed packages
You are free to uninstall any packages you've already added, but packages required by ArcGIS Pro are pinned and cannot be altered or removed. To uninstall a package, click the Uninstall button for the respective package. Since the default environment is read-only, it's packages cannot be removed. Create or clone an environment to remove packages.
Accessing conda from Python
Within the conda environment, you can open a Python session with the Python command and run Python scripts using the form Python yourscript.py. You can also access conda functionality using the conda command, such as listing the contents of the current environment (using conda list), and search for and access additional third-party libraries.