Problem with draw_networkx: module 'scipy.sparse' has no attribute 'coo_array'

3420 views
Skip to first unread message

Saverio

unread,
Apr 6, 2022, 2:46:53 PM4/6/22
to networkx-discuss
Hi,
sometimes when I use draw_networkx it returns the error in the object.
For example in an ipynb I receive the following:
nx.draw_networkx( G , node_size = 0 , with_labels = False )

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last) Input In [31], in <cell line: 1>() ----> 1 nx.draw_networkx( G , node_size = 0 , with_labels = False )
 File ~/.local/lib/python3.8/site-packages/networkx/drawing/nx_pylab.py:331, in draw_networkx(G, pos, arrows, with_labels, **kwds) 328 label_kwds = {k: v for k, v in kwds.items() if k in valid_label_kwds} 330 if pos is None: --> 331 pos = nx.drawing.spring_layout(G) # default to spring layout 333 draw_networkx_nodes(G, pos, **node_kwds) 334 draw_networkx_edges(G, pos, arrows=arrows, **edge_kwds) File <class 'networkx.utils.decorators.argmap'> compilation 13:4, in argmap_spring_layout_10(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed) 2 from os.path import splitext 3 from contextlib import contextmanager ----> 4 from pathlib import Path 6 import networkx as nx 7 from networkx.utils import create_random_state, create_py_random_state File ~/.local/lib/python3.8/site-packages/networkx/drawing/layout.py:476, in spring_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed) 474 if len(G) < 500: # sparse solver for large graphs 475 raise ValueError --> 476 A = nx.to_scipy_sparse_array(G, weight=weight, dtype="f") 477 if k is None and fixed is not None: 478 # We must adjust k by domain size for layouts not near 1x1 479 nnodes, _ = A.shape File ~/.local/lib/python3.8/site-packages/networkx/convert_matrix.py:907, in to_scipy_sparse_array(G, nodelist, dtype, weight, format) 904 row, col, data = [], [], [] 906 if G.is_directed(): --> 907 A = sp.sparse.coo_array((data, (row, col)), shape=(nlen, nlen), dtype=dtype) 908 else: 909 # symmetrize matrix 910 d = data + data AttributeError: module 'scipy.sparse' has no attribute 'coo_array'

Some hints to fix this?

Thanks

Saverio

Dan Schult

unread,
Apr 6, 2022, 5:40:04 PM4/6/22
to networkx...@googlegroups.com
Scipy introduced the `coo_array` in version 1.8.  So if you use a version of python with NetworkX 2.7 and Scipy 1.8 you should be fine, and if you have NetworkX before 2.7 and SciPy before 1.8 you should be fine.  But if you mix the new NetworkX with an older Scipy it will run into this issue.

Saverio lemme

unread,
Apr 7, 2022, 1:27:17 AM4/7/22
to networkx...@googlegroups.com
Ok.
Now all is fine.
Many thanks.
Saverio

Il giorno mer 6 apr 2022 alle ore 23:40 Dan Schult <dsc...@colgate.edu> ha scritto:
Scipy introduced the `coo_array` in version 1.8.  So if you use a version of python with NetworkX 2.7 and Scipy 1.8 you should be fine, and if you have NetworkX before 2.7 and SciPy before 1.8 you should be fine.  But if you mix the new NetworkX with an older Scipy it will run into this issue.

--
You received this message because you are subscribed to a topic in the Google Groups "networkx-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/networkx-discuss/z7WLqtll-f4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to networkx-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CA%2BXMcTMLMMYya-KurAoNB%2Bfiuv2SEOG0fAL_X7as%3DmX2MTfQGQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages