pyg-team / pyg-lib

Low-Level Graph Neural Network Operators for PyG
https://pyg-lib.readthedocs.io
Other
166 stars 41 forks source link

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

Open ryrl970311 opened 1 month ago

ryrl970311 commented 1 month ago

🐛 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

akihironitta commented 1 month ago

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