Skip To Content

Deploying custom Python packages for ArcGIS Server

ArcGIS Server includes Python 2.7 for Windows 64 bit. 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, 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:

  1. Sign in to your ArcGIS Server machine with the ArcGIS Server account, 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, 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.
  4. To activate the cloned environment, run proswap newenvname.
  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 on the Windows Task Manager Services tab or Windows Services. It will take a few minutes before all services are back online.
  7. Repeat steps 1 through 6 on each machine in your ArcGIS Server site, if applicable.

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

  1. Sign in to your ArcGIS Server machine.
  2. From the start menu, open the Python 3 Command Prompt. It may be in the ArcGIS Server folder, depending on your operating system.
  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 on the Windows Task Manager Services tab. All services will be back online in a few minutes.
  6. Repeat steps 1 through 5 on each machine in your ArcGIS Server site, if applicable.

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". 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".
  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 your cloned environment with activate <fullpath>\outsideenvname.
  4. 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.
  5. Once all the packages are installed, go to the ArcGIS Server administrator directory. 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" to the service properties when your 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, provide the full path to your cloned environment. A simplified service property JSON including the new condaEnvironmentPath property as

    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\\p20\\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.
  10. Your service restarts automatically.

Services published from ArcGIS Desktop

The following steps are for geoprocessing services published from ArcMap and the arcpy module based on Python 2.7. Follow the steps on each machine in your ArcGIS Server site. The package will be installed to the server's default Python 2.7 and will apply to all services published from ArcGIS Desktop.

  1. Download a Windows 64-bit version of the third-party package you want to install.
  2. Double-click the .msi or .exe file to install the package.

Custom packages are typically installed in the C:\Python27\ArcGISx6410.8\lib\site-packages directory.

Test custom Python packages for services published from ArcGIS Desktop

To test that the package installed properly, write a Python script that imports the package you installed, and run the script. If you are unfamiliar with running stand-alone scripts, follow the steps below.

  1. Open the terminal window.
  2. Run the server's Python 2.7 with the script as an argument, for example, <ArcGISServer_InstallDir>/arcgis/server/tools/python ~/projectX/mytestscript.py.

Note:

The Python libraries installed by an ArcGIS Server (Linux) installation are Windows 64-bit Python. Therefore, you should always use the Windows path separator (\) for stand-alone Python scripts when accessing data and other Python modules. Also, be aware that there is a Z:\ directory that is mapped to the Linux system's /. In a Python script, you can access data and other Python modules using Z:\ mapping. For example, data in /myuser/myproject/data can be accessed using z:\myuser\myproject\data.

This does not apply to Python scripts you publish from ArcGIS Desktop, because that publishing process converts all paths to the correct format.