pytorch_geometric: AttributeError: module 'scipy.sparse' has no attribute 'coo_array'

🐛 Describe the bug

code: from torch_geometric.datasets import KarateClub dataset = KarateClub()

bug: Traceback (most recent call last): File “F:\study\python\test\test4pyg.py”, line 2, in <module> dataset = KarateClub() File “F:\anaconda\envs\ai\lib\site-packages\torch_geometric\datasets\karate.py”, line 50, in init adj = nx.to_scipy_sparse_array(G).tocoo() File “F:\anaconda\envs\ai\lib\site-packages\networkx\convert_matrix.py”, line 921, in to_scipy_sparse_array A = sp.sparse.coo_array((d, (r, c)), shape=(nlen, nlen), dtype=dtype) AttributeError: module ‘scipy.sparse’ has no attribute ‘coo_array’

Environment

  • PyG version:2.0.4
  • PyTorch versn:1.10.1
  • OS:windows10
  • Python version:3.9.7
  • CUDA/cuDNN version:CU113
  • How you installed PyTorch and PyG (conda, pip, source):conda
  • Any other relevant information (e.g., version of torch-scatter):
  • pytorch-scatter:2.0.9
  • pytorch-sparse:0.6.13
  • pytorch-spline-conv:1.2.1
  • pytorch-cluster:1.6.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

coo_array appears only in scipy version 1.8.0

Looks like this is a version conflict between networkx and scipy. Can you upgrade both to see if this resolves your issues?

Same error using pyg-nightly and networkx 2.7.1. Downgrading to networkx==2.6.3 ‘solves’ the error for me.

Upgrading the networkx caused the same problem. These ones solved the problem for me scipy==1.8.0 networkx==2.6

I upgraded networkx and scipy, restarted vscode (powershell) and now it works.

I was calculating the network.pagerank of a graph on Google Colab when I encountered this problem. After going through all the suggestions, I executed the following to resolve the issue:

!pip install --upgrade scipy networkx

I tried this but still shows the same error. Can anyone suggest something that works? (My networkX version = 3.0 , scipy = 1.10)

I’m having the same problem, already upgraded both modules (networkx and scipy) but still getting the same error… AttributeError: module ‘scipy.sparse’ has no attribute ‘coo_array’

For me conda couldnt update to correct version but this works:

pip install --upgrade scipy networkx