Python has a rich collection of packages that can be used in ArcGIS Pro. To simplify the use of Python packages, ArcGIS Pro includes a package management system called conda. Conda takes the guesswork and hassle out of installing and updating packages and their dependencies.
To further extend the versatility and utility of Python packages, multiple installations of Python can coexist on a single workstation, independent of one another. Each of these installations is referred to as a Python environment. Each Python environment can have its own set of packages, allowing you to switch between sets of Python functionality without uninstalling and reinstalling packages each time.
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.
Work with Python environments
ArcGIS Pro includes a package manager that allows you to interact directly with conda without leaving 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 the Manage Environments button.
Remarque :
Starting with ArcGIS Pro 2.2, the default arcgispro-py3 environment is read-only and cannot be modified. Changes can be made by creating, or cloning, an environment in your user profile.
Create an environment
To create a clone of the default arcgispro-py3 environment, on the Manage Environments dialog box, click the Clone Default button . The new environment is a copy of the arcgispro-py3 environment, and only the default packages included with ArcGIS Pro will be installed.
You can also create a clone of any environment, including the arcgispro-py3 environment, by clicking the environment and then clicking the Clone button . This opens the Clone Environment dialog box, where you can set the environment's name and path.
By default, the environment is created in your %LocalAppData%\Esri\conda\envs folder. To create the environment in a different folder, click the Browse button on the Clone Environment dialog box and browse to the folder.
Activate an environment
The active Python environment is used to run any Python functionality executed in the application, such as code executed in the Python window, script tools, and Python toolbox tools. To change the active environment, on the Manage Environments dialog box, select the environment and click OK. After changing the active environment, you may need to restart ArcGIS Pro to reinitialize Python and use the new environment.
Remove an environment
To delete an environment, click the Remove button on the appropriate environment. The default arcgispro-py3 environment cannot be removed.
Add an environment
By default, only environments in two well-known locations (%PROGRAMFILES%\ArcGIS\Pro\bin\Python\envs and %LocalAppData%\Esri\conda\envs) are listed on the Manage Environments dialog box. To include an environment from another location, click the Add button .
Work with Python packages
One of the advantages of using conda is the availability and ease of installing many third-party Python packages in your current environment. You can use conda to install and manage any additional third-party dependencies to ensure that the package can be immediately used. Once the package is installed, you can use it in the Python window and in any of your script tools or Python toolboxes.
View installed packages
To see the currently installed packages, click the Installed Packages button. All third-party Python packages installed with ArcGIS Pro and any libraries you added are listed.
Update outdated packages
Over time, Python packages may become out of date. If there are updates you want to include, click the Update Packages button to see available updates. You can update a single package by clicking the package and clicking the Install button, or you can install all updates by clicking the Update All button. Some packages are pinned to a specific version and cannot be updated; these packages do not appear in the list even when updates are available. Since the default arcgispro-py3 environment is read-only, its packages cannot be updated. Create or clone an environment to update packages.
Install available packages
By clicking the Add Packages button, you can see the available Python packages that are compatible with your Python environment. By default, the latest version of each package is shown, but you can also access earlier versions by clicking the version number in the Version column. To install a Python package, click the package name in the Name column, change the version if necessary, 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.
Remove installed packages
You can uninstall any packages you add, but packages required by ArcGIS Pro are pinned and cannot be altered or removed. To uninstall a package, click the Uninstall button for the package. Since the default environment is read-only, its packages cannot be removed. Create or clone an environment to remove packages.
Access conda from Python
In 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 searching for and accessing additional third-party libraries.
For more information about using and working with conda, see Introduction to conda.
Network access for creating environments and installing packages
Creating conda environments and installing packages requires an internet connection. If you're trying to clone an environment from behind a firewall, the following sites may need to put on an allow list
in your network's firewall settings:
- https://conda.anaconda.org
- https://repo.anaconda.com
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?