1. 문제
아래와 같은 오류가 나와서 먼저 pyg-lib를 설치하려고 시도한다.
ImportError: 'NeighborSampler' requires either 'pyg-lib' or 'torch-sparse'
그러나 아래와 같이 설치가 되지 않는다.
!pip install pyg-lib
ERROR: Could not find a version that satisfies the requirement pyg-lib (from versions: none) ERROR: No matching distribution found for pyg-lib
torch-sparse도 마찬가지로 설치가 안 된다.
!pip install torch-sparse
Terminal
Collecting torch-sparse Downloading torch_sparse-0.6.18.tar.gz (209 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: scipy in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from torch-sparse) (1.15.2) Requirement already satisfied: numpy<2.5,>=1.23.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from scipy->torch-sparse) (1.26.4) Building wheels for collected packages: torch-sparse DEPRECATION: Building 'torch-sparse' using the legacy setup.py bdist_wheel mechanism, which will be removed in a future version. pip 25.3 will enforce this behaviour change. A possible replacement is to use the standardized build interface by setting the
--use-pep517 option, (possibly combined with --no-build-isolation), or adding a pyproject.toml file to the source tree of 'torch-sparse'. Discussion can be found at https://github.com/pypa/pip/issues/6334 Building wheel for torch-sparse (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [66 lines of output] /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/setuptools/dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: MIT License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ** !! self._finalize_license_expression() running bdistwheel /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/torch/utils/cppextension.py:529: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend. warnings.warn(msg.format('we could not find ninja.')) running build running build_py creating build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/init.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/add.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/bandwidth.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/cat.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/coalesce.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/convert.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/diag.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/eye.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torchsparse/indexselect.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torchsparse/maskedselect.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/matmul.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/metis.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/mul.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/narrow.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/permute.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/reduce.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/rw.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/saint.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/sample.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/select.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/spadd.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/spmm.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/spspmm.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/storage.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/tensor.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/testing.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/transpose.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/typing.py -> build/lib.linux-x86_64-cpython-310/torch_sparse copying torch_sparse/utils.py -> build/lib.linux-x86_64-cpython-310/torch_sparse running egg_info writing torch_sparse.egg-info/PKG-INFO writing dependency_links to torch_sparse.egg-info/dependency_links.txt writing requirements to torch_sparse.egg-info/requires.txt writing top-level names to torch_sparse.egg-info/top_level.txt reading manifest file 'torch_sparse.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files matching '' found under directory 'third_party/parallel-hashmap/css' warning: no previously-included files matching '' found under directory 'third_party/parallel-hashmap/html' warning: no previously-included files matching '' found under directory 'third_party/parallel-hashmap/tests' warning: no previously-included files matching '' found under directory 'third_party/parallel-hashmap/examples' warning: no previously-included files matching '' found under directory 'third_party/parallel-hashmap/benchmark' warning: no previously-included files matching '' found under directory 'test' warning: no previously-included files matching '*' found under directory 'benchmark' adding license file 'LICENSE' writing manifest file 'torch_sparse.egg-info/SOURCES.txt' running build_ext error: [Errno 2] No such file or directory: '/usr/local/cuda-11.8/bin/nvcc' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for torch-sparse Running setup.py clean for torch-sparse Failed to build torch-sparse ERROR: Failed to build installable wheels for some pyproject.toml based projects (torch-sparse)2. 해결
torch와 CUDA 버전에 맞게 설치해야 문제가 해결된다. 먼저 아래 코드를 실행한다.
import torch # Print PyTorch version print(torch.__version__)
내 경우로는 2.6.0+cu124라고 나온다.
이 값을 아래 명령어에서 {torch 버전}에 넣고 실행한다.
!pip install pyg_lib torch_scatter torch_sparse -f <https://data.pyg.org/whl/torch->{torch 버전}.html