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 now 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.
When updating ArcGIS Pro from a previous version, the default arcgispro-py3 environment 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. Non-default environments will not be altered.
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 pristine copy of the default arcgispro-py3 environment; only the default packages included with ArcGIS Pro will be installed.
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.
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.
Removing an environment
To delete an environment, click the Remove button on the appropriate environment.
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 an 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 by ArcGIS Pro and cannot be updated; these particular packages will not appear in the list even when updates are available.
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 particular Python package, click its name under the Name column, change the version if needed, and click the Install button.
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.
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.