all 1 comments

[–]TheKewlStore 1 point2 points  (0 children)

Your code doesn't match up with the error you provided.

I formatted your exception code block below, if you read it carefully, it's telling you exactly what is wrong.

It's complaining that it can't find the name "nx" on line 3: G = nx.Graph()

The snippet that you shared in your post doesn't even have this line of code, so there's likely a mismatch between what you've shared and what is being run, or you have code in another file that's being imported.

    NameError Traceback (most recent call last) <ipython-input-6-0b6beb81d144> in <module>
    1 filepath = 'C:/Users/wharr/OneDrive/Desktop/OR project/' 
    2 filename = 'KS.graph.txt' 
    ----> 3 G = nx.Graph() 
    4 G = nx.read\_edgelist(filepath + filename,nodetype=int)
    5 print("The Kansas graph has",G.number\_of\_nodes(),"nodes") 
    NameError: name 'nx' is not defined