ERROR

ArcPy fails to import on a machine authorized for ArcGIS Server

Last Published: April 25, 2020

Error Message

The following exception is raised when ArcPy fails to import a python script or IDE.

"Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 568, in <module>
env = GPEnvironments(gp)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 565, in GPEnvironments
return GPEnvironment(geoprocessor)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 521, in __init__
self._refresh()
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 523, in _refresh
envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized"

Cause

This issue occurs when ArcGIS Desktop and ArcGIS Server are installed on the same machine but only ArcGIS Server is authorized.

When a module is imported into Python, a list of paths is searched to find the module. This list is defined in the 'sys.path' variable. This 'sys.path' variable contains the location of the script, paths defined in the PYTHONPATH environment variable, and installation dependent default paths. Additionally, adding a path configuration file (.pth) to any of these locations appends additional paths to the 'sys.path' variable. When the module is found it attempts to import it and stops scanning the list of paths.

ArcGIS Desktop and ArcGIS Server lay down separate installs of the ArcPy module in their respective install locations. In addition, ArcGIS Desktop and ArcGIS Server place unique path configuration files (desktop.pth and server.pth) in the Lib\site-packages folder of the install location for Python.

• Desktop.pth contains the path to the ArcGIS Desktop install for ArcPy.
• Server.pth contains the path to the ArcGIS Server install for ArcPy.


When ArcPy is imported as a result of the process described above, the path to the ArcGIS Desktop install of ArcPy is found first. When it is imported it attempts to find a license for ArcGIS Desktop and fails with the exception shown above.

Solution or Workaround

To resolve this error, remove the ArcGIS Desktop path to ArcPy from the sys.path variable. The easiest way to do this is by removing or renaming desktop.pth, the ArcGIS Desktop path configuration file.

  1. Browse to the Lib\site-packages folder of the install location for Python.

    Note:
    By default, when installed with ArcGIS Desktop this would be
    C:\Python26\ArcGIS10.0\Lib\site-packages.


  2. Rename the desktop.pth file to desktop.txt.

    Note:
    In the future, to use ArcPy in Python scripts with an ArcGIS Desktop license, rename this file back to desktop.pth.

Article ID:000011275

Software:
  • ArcGIS Server

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic