Skip To Content

Deploy custom Python packages for ArcGIS Server

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 steps below 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:

  1. Sign in to your ArcGIS Server machine and open the command prompt window as an administrator.
  2. Change the directory to <install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\Scripts.
  3. Clone the server's default Python environment with a new environment name. The suggested location is at the ArcGIS Server installation's Python environment directory. Run the command conda create --clone arcgispro-py3 --prefix "<install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\newenvname" --pinned --no-shortcuts using a sample newenvname. Replace the prefix with your installation directory and the new environment name. Alternatively, you can specify a location outside the installation directory.
  4. Run conda proswap -n newenvname --all-users to activate the cloned environment.

    Providing the --all-users argument is optional if you signed in to your machine as the ArcGIS Server account user; otherwise, it is a required argument. If the cloned conda environment is outside the suggested location, provide the full path to that location using conda proswap -p "<full-path-to-cloned-directory>" --all-users.

  5. Install the third-party Python packages by running conda install.

    Only use pip install if conda install is not available.

  6. Restart the ArcGIS Server service.

    It will take a few minutes before all services are back online.

  7. Repeat steps 1 through 6 on all other machines in your ArcGIS Server site for a multiple-machine deployment.

Add more packages

To add more packages to the existing conda environment, follow these steps:

  1. Sign in to your ArcGIS Server machine. You may need administrative privileges depending on the location of your existing conda environment.

    You may need administrative privileges depending on the location of your existing conda environment.

  2. From the start menu, open the Python 3 Command Prompt. It may be in the ArcGIS Server folder, depending on your operating system. If it is not available in the start menu, you can run proenv.bat at <install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\Scripts.
  3. Run conda install for the packages that need to be deployed.

    Only use pip install if conda install is not available.

  4. Restart the geoprocessing service in ArcGIS Server Manager.
  5. Optionally, restart the ArcGIS Server service.

    All services will restart in a few minutes.

  6. 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:

  1. Sign in to your ArcGIS Server machine, and open the Python 3 Command Prompt from the start menu.

    It is recommended that you run the command prompt as an administrator, otherwise, you may not be able to clone the environment to certain directories.

  2. 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" --pinned --no-shortcuts. Replace the prefix with your installation directory and the new environment name. To clone the environment to any other directories outside the ArcGIS Server installation directory, run conda create --clone arcgispro-py3 --prefix "<fullpath>\outsideenvname" --pinned --no-shortcuts.
  3. Activate the new environment in the command prompt window with activate newenvname. If you are using a directory outside the ArcGIS Server installation's Python environment directory, provide the full path to the cloned environment with activate <fullpath>\outsideenvname.
  4. Install the 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.

  5. Once all the packages are installed, go to the ArcGIS Server administrator directory, and in Resources at the bottom of the page, go to services.
  6. Select the geoprocessing service for which you want to specify a Python environment.
  7. In Supported Operations at the bottom of the page, click edit.
  8. In the service JSON, add the key value pair "condaEnvironmentPath": "newenvname" or "condaEnvironmentPath": "<full path to newenvname>" to the service properties when the cloned environment is in the ArcGIS Server installation's Python environment directory. If you are using a directory outside the ArcGIS Server installation's Python environment directory, you must provide the full path to your cloned environment. A simplified service property JSON including the new condaEnvironmentPath property is as follows:

    Deploy custom Python packages for ArcGIS Server

    Simplified service properties with a cloned Python environment in the ArcGIS Server installation's Python environment directory.

    {
     "serviceName": "gvonly",
     "type": "GPServer",
     "description": "",
     "allowedUploadFileTypes": "",
     "properties": {
      "toolbox": "C:\\arcgisserver\\directories\\arcgissystem\\arcgisinput\\gvonly.GPServer\\extracted\\p30\\gvonly.tbx",
      "condaEnvironmentPath": "newenvname",
      "showMessages": "INFO"
     },
     "portalProperties": {
      "isHosted": false,
      "portalItems": [{
       "itemID": "4921223df97744a593d0b776666b9da9",
       "type": "GPServer"
      }]
     },
     "extensions": [{
      "typeName": "WPSServer",
      "properties": {
       "serviceType": "",
       "name": ""
      }
     }],
     "frameworkProperties": {},
     "datasets": []
    }

  9. Click the Save Edits button to save your edits.

The service restarts automatically.

Upgrade a cloned Python environment after an ArcGIS Server upgrade

Traditionally, when upgrading ArcGIS Server to a newer version, you would need to discard the previously cloned environments. You would then need to clone the Python environment from the upgraded ArcGIS Server and reconfigure your services.

At ArcGIS Server 11.0, use the conda proup command to upgrade the cloned Python environments from earlier versions of ArcGIS Server by complete thing the following steps:

  1. Sign in to your ArcGIS Server machine and open the command prompt window as an administrator.
  2. Change the directory to <install>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\Scripts.
  3. Activate the conda environment you want to upgrade by running conda activate <environment name or path>.
  4. Once activated, upgrade the environment by running either conda proup -n <environment name> or conda proup -p <environment directory path>.
  5. After the Python environment upgrade, restart all the geoprocessing services used by this conda environment, or restart the ArcGIS Server service.

To learn more about the conda proup command, use conda proup --help. This function cannot be used to downgrade an environment after a downgrade of ArcGIS Server. This function is not available in a disconnected environment either.