Trying to create a geoprocessing service on ArcGIS for Server 10.3 to do some routing on a networkx graph. The service only works on the first call. It fails on subsequent calls. I note this because when I restart the service and make a fresh call, I get expected results.

Below is the published script via a toolbox.

import os
import networkx as nx
import arcpy

LOCAL_WS = r"C:\inetpub\wwwroot\src.gdb"
EDGES_FC = os.path.join(LOCAL_WS, "EDGES")
MAINS_FC = os.path.join(LOCAL_WS, "MAINS")

M = nx.MultiGraph()
edge_fields = ["LOC1", "LOC2", "CABLE"]
with arcpy.da.SearchCursor(EDGES_FC, edge_fields) as ecur:
    for erow in ecur:
        loc1 = erow[0]
        loc2 = erow[1]
        cable = erow[2]

        # Add the segment to the graph
        M.add_edge(loc1, loc2, key=cable)

def checkIsolated(a_node, z_node):
        paths = nx.dijkstra_path(M, source=a_node, target=z_node)
        return "HAS PATH"
    except nx.NetworkXNoPath:
        return "NO PATH"
        return "FAILED ROUTING"

if __name__ == "__main__":
    # Isolation Test
    a_loc = arcpy.GetParameterAsText(0)
    z_loc = arcpy.GetParameterAsText(1)
    checkResult = checkIsolated(a_loc, z_loc)
    arcpy.SetParameterAsText(2, checkResult)

This is the error logged by ArcGIS for Server:

File  "E:\arcgisserver\directories\arcgissystem\arcgisinput\FindIsolated.GPServer\extracted\v101\arcgisservermxds\NetworkXTools.tbx#FindIsolated.py", line 11, in File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\__init__.py", line 128, in import networkx.drawing File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\drawing\__init__.py", line 6, in from . import nx_pydot File "E:\Python27\ArcGISx6410.3\lib\site-packages\networkx\drawing\nx_pydot.py", line 27, in from pkg_resources import parse_version File "E:\Python27\ArcGISx6410.3\lib\site-packages\pkg_resources\__init__.py", line 50, in from pkg_resources.extern import six File "E:\Python27\ArcGISx6410.3\lib\site-packages\pkg_resources\extern\__init__.py", line 44, in load_module mod = sys.modules[extant] AttributeError: 'NoneType' object has no attribute 'modules' Failed to execute (FindIsolated).

The networkx library was installed into in the 64-bit version of the Python on Windows 2008 Server (that comes bundled with ArcGIS for Server). IIS is our web server.

Any thoughts?

(My hope is to have an active web service holding the networkx graph and not have to recreate it everytime I want to route some nodes.)

  • A few things to try, 1. In Server Manager, go into the properties of the GP Service, under Parameters - Set the "Message Level" to INFO if it's set to "None". INFO should log more. Execute the GP Service at the REST endpoint after making that change to see if you get more info. 2. Stop the service. In File Explorer, dig down to "E:\arcgisserver\directories\arcgissystem\arcgisinput\FindIsolated.GPServer\extracted\v101\arcgisservermxds\". find the copied script and examine it for differences compared to the original. You could make a new folder connection to E:\arcgisserver and investigate
    – Don
    Commented Nov 8, 2017 at 13:11
  • The error originally noted was already from a VERBOSE log output. Changing to DEBUG level didn't show anything new. As for the the script, the only modification the publishing process did was add an extra line building a variable: g_ESRI_variable_1 = os.path.join(arcpy.env.packageWorkspace,u'src.gdb') and LOCAL_WS = g_ESRI_variable_1
    – Eok
    Commented Nov 13, 2017 at 22:59

1 Answer 1


This same thing occurs for me in ArcMap 10.4.1 Python 2.7.10 32bit and ArcGIS Server 10.5.1. Python 2.7.13 32bit. It occurs for Networkx 2.1 but does not occur for Networkx 1.7 The issue can be reproduced by creating a simple tool for ArcMap:

import arcpy
import networkx as nx
G = nx.krackhardt_kite_graph()

Like the original post this runs fine the first time, but fails on a repeated call in ArcMap. However, I can do repeated executions when I run this simple tool in my IDE (PyCharm).

The issue seems to have something to do with pkg_resources which belongs to setuptools. I have setuptools 39.0.1
I have read dozens of issues that may or may not be related, such as: https://github.com/pypa/setuptools/issues/885

I am still looking for a good solution, but for now my hack is to comment out the last two lines of networkx\ __ init __.py

# import networkx.drawing
# from networkx.drawing import * 
  • By stumbling on my own question upon revisiting this tool, this hack works well enough for my purposes since I don't need the drawing capabilities.
    – Eok
    Commented Jul 31, 2018 at 21:26
  • This hack no longer is sufficient for me because now it is happening with a different import. Again the traceback leads to: from pkg_resources.extern import six and then mod = sys.modules[extant] and AttributeError: 'NoneType' object has no attribute 'modules' Any advice would be greatly appreciated.
    – Lowry
    Commented Sep 13, 2018 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.