pyg-lib icon indicating copy to clipboard operation
pyg-lib copied to clipboard

`import pyg_lib` fails due to `AttributeError: module 'pyg_lib' has no attribute 'ops'`

Open ruoyeruolan opened this issue 1 year ago • 1 comments

🐛 Describe the bug

import torch_sparse

When I run the code above, it raise an error that pyg_lib has no attribute 'ops'. How shoud I solve this problem?

AttributeError                            Traceback (most recent call last)
Cell In[48], line 2
      1 # import pyg_lib
----> 2 import torch_sparse

File ~/venvs/versions/3.12.4/torch/lib/python3.12/site-packages/torch_sparse/__init__.py:39
     31     if t_major != major:
     32         raise RuntimeError(
     33             f'Detected that PyTorch and torch_sparse were compiled with '
     34             f'different CUDA versions. PyTorch has CUDA version '
     35             f'{t_major}.{t_minor} and torch_sparse has CUDA version '
     36             f'{major}.{minor}. Please reinstall the torch_sparse that '
     37             f'matches your PyTorch install.')
---> 39 from .storage import SparseStorage  # noqa
     40 from .tensor import SparseTensor  # noqa
     41 from .transpose import t  # noqa

File ~/venvs/versions/3.12.4/torch/lib/python3.12/site-packages/torch_sparse/storage.py:7
      4 import torch
      5 from torch_scatter import scatter_add, segment_csr
----> 7 from torch_sparse.utils import Final, index_sort
      9 layouts: Final[List[str]] = ['coo', 'csr', 'csc']
     12 def get_layout(layout: Optional[str] = None) -> str:

File ~/venvs/versions/3.12.4/torch/lib/python3.12/site-packages/torch_sparse/utils.py:5
      1 from typing import Any, Optional, Tuple
      3 import torch
----> 5 import torch_sparse.typing
      6 from torch_sparse.typing import pyg_lib
      8 try:

File ~/venvs/versions/3.12.4/torch/lib/python3.12/site-packages/torch_sparse/typing.py:4
      2     import pyg_lib  # noqa
      3     WITH_PYG_LIB = True
----> 4     WITH_INDEX_SORT = hasattr(pyg_lib.ops, 'index_sort')
      5 except ImportError:
      6     pyg_lib = object

AttributeError: module 'pyg_lib' has no attribute 'ops'

Environment

  • pyg-lib version: 0.4.0+pt23
  • PyTorch version:2.3.1
  • OS: MacOS
  • Python version:3.12.4
  • CUDA/cuDNN version:
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information:

ruoyeruolan avatar Jul 27 '24 10:07 ruoyeruolan

What's the command you ran to install pyg-lib?

akihironitta avatar Jul 27 '24 13:07 akihironitta