At ArcGIS Enterprise 10.5 and later, a Python 3-based conda environment is included with ArcGIS Server.
The Python installation of ArcGIS Server includes packages such as numpy and matplotlib. However, if you want to install additional custom Python packages, follow the steps below.
Services published from ArcGIS Pro
Similar to ArcGIS Pro, ArcGIS Server uses conda to manage Python environments. Starting at ArcGIS Server 10.7.1, you can specify a Python environment for all geoprocessing services. Starting at ArcGIS Server 10.8.1, you can specify a Python environment for a single geoprocessing service.
The following steps are for geoprocessing services published from ArcGIS Pro or using ArcPy. For more information about the Python environment in ArcGIS Pro, see Python in ArcGIS Pro. It is recommended that you clone the default Python environment to make updates. Only one Python environment at a time can be activated for ArcGIS Server.
For additional information about using and working with conda, see the introduction to conda.
Specify a Python environment for all geoprocessing services
To deploy third-party Python packages with ArcGIS Server, use the following steps for each machine in your site:
- Sign in to your ArcGIS Server machine with the ArcGIS Server account, and open the command prompt window as an administrator.
- Change the directory to <install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\Scripts.
- Clone the server's default Python environment with a new environment name, for example, newenvname, in the ArcGIS Server installation's Python environment directory with the command conda create --clone arcgispro-py3 --prefix "<install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\newenvname". Replace the prefix with your installation directory and the new environment name.
- To activate the cloned environment, run proswap newenvname.
- Install the third-party Python packages by running conda install. Only use pip install if conda install is not available.
- Restart the ArcGIS Server service on the Windows Task Manager Services tab or Windows Services. It will take a few minutes before all services are back online.
- Repeat steps 1 through 6 on all other machines in your ArcGIS Server site for a multiple machine deployment.
To add more packages to the existing conda environment, follow these steps:
- Sign in to your ArcGIS Server machine.
- From the start menu, open the Python 3 Command Prompt. It may be in the ArcGIS Server folder, depending on your operating system.
- Run conda install for the packages that need to be deployed. Only use pip install if conda install is not available.
- Restart the geoprocessing service in ArcGIS Server Manager.
- Optionally, restart the ArcGIS Server service on the Windows Task Manager Services tab. All services will be back online in a few minutes.
- Repeat steps 1 through 5 on each machine in your ArcGIS Server site when you have a multiple machine deployment.
Specify a Python environment for a single geoprocessing service
Clone the server default Python environment, install third-party Python packages, and edit the service properties of your geoprocessing service using the following steps:
- Sign in to your ArcGIS Server machine with the ArcGIS Server account, and open the command prompt window as an administrator.
- Change the directory to <install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\Scripts.
- Clone the server's default Python environment with a new environment name, for example, newenvname, in the ArcGIS Server installation's Python environment directory with the command conda create --clone arcgispro-py3 --prefix "<install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\newenvname". Replace the prefix with your installation directory and the new environment name.
- Activate the new environment in the command prompt window with activate newenvname.
- Install your Python packages with conda install packagename=version. It is optional, but a best practice, to align the package version you used in ArcGIS Pro during the publishing process and the package version installed on the server.
- Once all the packages are installed, go to the ArcGIS Server administrator directory. In Resources at the bottom of the page, go to services.
- Select the geoprocessing service for which you want to specify a Python environment.
- In Supported Operations at the bottom of the page, click edit.
- In the service JSON, add the key value pair "condaEnvironmentPath": "<install>\\ArcGIS\\Server\\framework\\runtime\\ArcGIS\\bin\\Python\\envs\\newenvname" to the properties.
Sample Service Properties showing limited key-values for illustrative purposes.
{ "serviceName": "gvonly", "type": "GPServer", "description": "", "allowedUploadFileTypes": "", "properties": { "toolbox": "C:\\arcgisserver\\directories\\arcgissystem\\arcgisinput\\gvonly.GPServer\\extracted\\p20\\gvonly.tbx", "condaEnvironmentPath": "C:\\Program Files\\ArcGIS\\Server\\framework\\runtime\\ArcGIS\\bin\\Python\\envs\\flaskonly" }, "portalProperties": { "isHosted": false, "portalItems": [{ "itemID": "4921223df97744a593d0b776666b9da9", "type": "GPServer" }] }, "extensions": [{ "typeName": "WPSServer", "properties": { "serviceType": "", "name": "" } }], "frameworkProperties": {}, "datasets": [] }
- Click the Save Edits button to save your edits.
- Your service restarts automatically.