Reputation: 1288
I have the code below for importing graphs saved as JSONs, and it works perfectly on 2 of 3 computers, all running the same WinPython v3.6. On the third computer it returns: AttributeError: module 'networkx' has no attribute 'json_graph'
.
import json
import networkx as nx
def openJSONDiGraph(filename):
with open(filename, encoding='utf-8-sig') as f:
js_graph = json.load(f)
return nx.json_graph.node_link_graph(js_graph, directed=True, multigraph=False)
thisNetwork = openJSONDiGraph(networkFileAddress)
This code has worked perfectly for two years to import graphs saved as JSON. It previously worked on this computer too, but I had to reinstall my whole Python (using the same exact installer) recently, and now it fails.
This is similar to this post, so I tried to include from networkx.readwrite import json_graph
instead, but this returns ImportError: cannot import name 'to_tuple'
. Making me think there is something wrong with my NetworkX installation or its dependencies.
I uninstalled and reinstalled NetworkX 2.4 using pip (the other computers are running v2.1, but that shouldn't make a difference here), and the problem persists.
This question is very similar to this one, but there is no solution posted there.
How do I fix my NetworkX installation or change my code to get this to work as it usually does?
Upvotes: 0
Views: 346
Reputation: 1288
Without anything else to try, and contrary to my expectations, downgrading from NetworkX v2.4 to v2.1 solved this problem. I didn't see anything in the v2.4 documentation that suggested this would be different, but clearly something in the readwrite module has changed.
I could delete the question at this point, but I think it's better to leave it here for posterity in case anybody confronts similar issues while trying to upgrade.
Upvotes: 2