Frequently asked question

Why do Python scripts fail on a machine with both ArcGIS for Server and Desktop installed?

Last Published: August 5, 2022

Answer

Starting at version 10.1, ArcGIS for Server is a 64-bit application. ArcMap is a 32-bit application, meaning if both products are installed on the same machine, there are 32-bit and a 64-bit installations of Python. If a Python script is executed against the 64-bit install of Python and import arcpy, it uses the ArcGIS Server install of arcpy. Some scripts written to work with ArcMap fail to execute when run against the ArcGIS Server install of arcpy due to unsupported tools or data sources.

By default, Windows associates the .py file with the last installed version of Python, so if 32-bit Python is installed (Desktop) first, and then 64-bit Python is installed (Server), the 64-bit version is associated with the file extension. File associations are used to determine which executable should be used to execute the file in many scenarios. For example, a .py file is opened in Windows Explorer, the file association determines which version of Python is used to execute the script. In the case described above, this means the 64-bit version is used. In addition, if a Python script is called from the command line by just passing in the path to the .py file, file associations are used to determine which version of Python is used.

When calling a script from the command line, this can be resolved by explicitly calling the correct version of Python and then passing in the path to the script followed by any arguments to the script.

[O-Image]

To change which version of Python is associated with the .py file, right-click any .py file in Windows Explorer and click Open with > Choose Default Program. From the 'Open with' dialog, browse to and select the 32-bit install of Python. (When using the default install location with ArcGIS, this path is C:\Python27\ArcGIS10.1\python.exe). Select OK to commit the change. Now when file associations are relied upon to select the right version of Python, the 32-bit install is used.

IDEs also target a specific version of Python. IDEs like PythonWin or PyScripter generally have specific setups for 32-bit or 64-bit. If it is desired to work against the 32-bit install of Python, then the 32 bit-version of the IDE must be installed.

Since IDLE is installed by default with Python, 32-bit and 64-bit versions of IDLE are installed. To run a script in IDLE against the 32-bit version of Python it is necessary to run the 32-bit version of IDLE. IDLE can be launched by double-clicking idle.bat from <PythonInstallLocation>\Lib\idlelib.

If unsure which version is being run by the script, the following code can be used to determine this:

import sys
print sys.version

In the print statement, either 32-bit or 64-bit is identified in addition to the release version of Python.

Article ID:000011711

Software:
  • ArcGIS Server

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic