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.
Note:
If using a cloned environment that was created before applying the ArcGIS Server log4j Patch, activate the environment by running conda activate your_environment, and run conda update saspy to resolve the security vulnerability for the log4j used with the older version of saspy in the cloned environment. If the patch is already installed, include the --pinned flag when cloning the default environment, detailed in the instructions below. After activating the cloned environment, run conda update saspy to ensure that the log4j security vulnerability will not be present in the cloned environment.
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" --pinned --no-shortcuts. 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 each machine in your ArcGIS Server site, if applicable.
To add more packages to the existing conda environment, follow these steps:
- Sign in to your ArcGIS Server machine. You may need an account with administrative privileges.
- 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, 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:
- 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.
- 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.
- 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.
- 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": "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.
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": [] }
- Click the Save Edits button to save your edits.
- 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.
- Download a Windows 64-bit version of the third-party package you want to install.
- 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.
- Open the terminal window.
- 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.