ArcGIS and Python
Please familiarize yourself with the ArcGIS Pro Python Reference section of the ArcGIS Pro documentation.
⚠ This page is for ArcGIS Pro 3.1 or newer. For older versions, see the legacy page.
Conda Environments
ArcGIS Pro uses Conda to manage multiple environments, as documented in ArcGIS Pro and Conda.
File locations
This section describes where various files related to ArcGIS Pro’s Python installation can be found.
The text surrounded by percent signs (%
) are environment variables.
Description | Location |
---|---|
Default Conda environment (Python EXE, etc.) | %PROGRAMFILES%\ArcGIS\Pro\bin\Python\envs\arcgispro-py3 |
Conda and batch files | %PROGRAMFILES%\ArcGIS\Pro\bin\Python\Scripts |
All users’ scripts folder | %PROGRAMFILES%\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Scripts |
Per-user scripts folder (installed via pip) | %APPDATA%\Python\Python 39\Scripts 1 |
Custom Conda environments | %LOCALAPPDATA%\ESRI\conda\envs\ your-env-name |
Scripts installed via Conda | %LOCALAPPDATA%\ESRI\conda\envs\ your-env-name\Scripts |
List Conda environments
Using Conda CLI commands (should work cmd.exe or elsewhere):
conda env list
Using Powershell to find environments by examining the directory where Conda environments are stored.
Get-ChildItem "$env:LOCALAPPDATA\ESRI\conda\envs" -Directory
Creating custom packages
Powershell profile setup
Put this into your Powershell profile script to have Powershell only start Conda when starting in a folder containing Python files containing the text arcpy
.
It will also add a function called Initialize-Conda
which will let you do this manually.
# Examples for pre-Conda setup.
# Setup posh-git
Import-Module posh-git
# If you use oh-my-posh, set it up before setting up Conda if you want
# the prompt to display your current conda environment.
oh-my-posh init pwsh | Invoke-Expression
# --> Conda stuff starts here <--
# Detect if conda should be loaded.
New-Variable -Name hasArcPy -Value (
# Get all the Python files and filter to only those containing the text "arcpy".
(Get-ChildItem **\*.py,**\*.pyt -Recurse | Select-String 'arcpy' -List
# Select only the first item. We only need to determine if Python files containing
# "arcpy" are present. Once we've detected one we can stop looking.
| Select-Object -First 1
# Return true if matches were found, false otherwise.
).Length -ge 1
) -Scope Private
<#
.SYNOPSIS
You can use this function to initialize conda if it is not auto-detected.
#>
function Initialize-Conda {
Write-Progress "Initializing Conda"
# To see what the command below is doing, run that line without the trailing `| Invoke-Expression`.
(& "C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
}
# Initialize Conda only if an arcpy script is detected.
if ($hasArcPy) {
Initialize-Conda
} else {
Write-Host "Conda was not initialized automatically. If you would like to do so, use the Initialize-Conda command."
}
# Remove the hasArcPy variable so it is not present after Powershell has been initialized.
Remove-Variable hasArcPy
-
The number after the word Python may differ depending on the version of ArcGIS Pro installed. ArcGIS Pro 3.1 comes with Python 3.9.16, so the folder name is
Python39
. ↩