Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Building wheel for torch-sparse (setup.py) ... error" when installing torch_sparse via pip3 #5015

Open
Jerry-jwz opened this issue Jul 20, 2022 · 10 comments

Comments

@Jerry-jwz
Copy link

Jerry-jwz commented Jul 20, 2022

😵 Describe the installation problem

When I was installing torch-sparse through the command:
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html,
I was totally confused by the following error:

Looking in links: https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html
Collecting torch-sparse
  Using cached torch_sparse-0.6.14.tar.gz (51 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: scipy in ./anaconda3/envs/pytorch/lib/python3.8/site-packages (from torch-sparse) (1.8.1)
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in ./anaconda3/envs/pytorch/lib/python3.8/site-packages (from scipy->torch-sparse) (1.23.0)
Building wheels for collected packages: torch-sparse
  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
  ╰─> [55 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.8
      creating build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/__init__.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/add.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/bandwidth.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/cat.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/coalesce.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/convert.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/diag.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/eye.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/index_select.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/masked_select.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/matmul.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/metis.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/mul.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/narrow.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/padding.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/permute.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/reduce.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/rw.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/saint.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/sample.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/select.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/spadd.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/spmm.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/spspmm.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/storage.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/tensor.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/transpose.py -> build/lib.linux-x86_64-3.8/torch_sparse
      copying torch_sparse/utils.py -> build/lib.linux-x86_64-3.8/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 'test'
      adding license file 'LICENSE'
      writing manifest file 'torch_sparse.egg-info/SOURCES.txt'
      running build_ext
      /home/jiangwenzhao/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/utils/cpp_extension.py:782: UserWarning: The detected CUDA version (11.6) has a minor version mismatch with the version that was used to compile PyTorch (11.3). Most likely this shouldn't be a problem.
        warnings.warn(CUDA_MISMATCH_WARN.format(cuda_str_version, torch.version.cuda))
      building 'torch_sparse._convert_cpu' extension
      creating build/temp.linux-x86_64-3.8
      creating build/temp.linux-x86_64-3.8/csrc
      creating build/temp.linux-x86_64-3.8/csrc/cpu
      gcc -pthread -B /home/jiangwenzhao/anaconda3/envs/pytorch/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_PYTHON -Icsrc -I/home/jiangwenzhao/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/include -I/home/jiangwenzhao/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/jiangwenzhao/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/include/TH -I/home/jiangwenzhao/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/include/THC -I/home/jiangwenzhao/anaconda3/envs/pytorch/include/python3.8 -c csrc/convert.cpp -o build/temp.linux-x86_64-3.8/csrc/convert.o -O2 -Wno-sign-compare -DAT_PARALLEL_OPENMP -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=_convert_cpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14
      gcc: fatal error: cannot execute 'cc1plus': execvp: No such file or directory
      compilation terminated.
      error: command '/home/jiangwenzhao/anaconda3/envs/pytorch/bin/gcc' failed with exit code 1
      [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

Before this, I had just fixed a warning saying 'Your compiler (g++ 4.8.5) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 5.0 and above', by 'conda install -c conda-forge gxx=9.4.0 gcc=9.4.0'. However, I am totally stuck with the above error. Hope anyone could help!

If you need any other info, please let me know.

Environment

  • PyG version:2.04
  • PyTorch version:1.10.0
  • OS:CentOS Linux release 7.9.2009 (Core)
  • Python version:3.8
  • CUDA/cuDNN version:11.3
  • How you installed PyTorch and PyG (conda, pip, source):pip
  • torch_cluster:1.6.0
  • torch_scatter:2.0.9
  • torch_spline_conv:1.2.1
  • gcc & g++: 9.4.0
@downeykking
Copy link

downeykking commented Jul 20, 2022

I encountered the same question with you and i solved it using this command:
pip install torch-sparse==0.6.13 -f https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html

@Jerry-jwz
Copy link
Author

I encountered the same question with you and i solved it using this command: pip install torch-sparse==0.6.13 -f https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html

It works! Thanks! But still don't know why torch-sparse-0.6.14 causes this trouble.

@downeykking
Copy link

I encountered the same question with you and i solved it using this command: pip install torch-sparse==0.6.13 -f https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html

It works! Thanks! But still don't know why torch-sparse-0.6.14 causes this trouble.

check 'https://data.pyg.org/whl/index.html'. It only has torch-sparse-0.6.13 and torch-sparse-0.6.14 does not released yet. maybe that is the reason.

@rusty1s
Copy link
Member

rusty1s commented Jul 20, 2022

We only build new versions for the two latest PyTorch releases. That‘s why 0.6.13 is the last version for PyTorch 1.10.

@LingjieBao1998
Copy link

wonderful! It help me a lot! Thanks for your goodness

@harshy105
Copy link

In my environment, I had pytorch 2.0.1 with cuda 11.8 on windows. And none of the provided comment worked for me. Then I found the comment on PyG installation guide: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html

pip install torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

This worked just fine

@Armanasq
Copy link

I have tried to install pip install torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

But still I could not load torch_sparse


OSError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import torch_sparse

File /media/ssrc/DataBase/cmu/lib/python3.8/site-packages/torch_sparse/init.py:19
17 spec = cuda_spec or cpu_spec
18 if spec is not None:
---> 19 torch.ops.load_library(spec.origin)
20 else: # pragma: no cover
21 raise ImportError(f"Could not find module '{library}_cpu' in "
22 f"{osp.dirname(file)}")

File /media/ssrc/DataBase/cmu/lib/python3.8/site-packages/torch/_ops.py:852, in _Ops.load_library(self, path)
847 path = _utils_internal.resolve_library_path(path)
848 with dl_open_guard():
849 # Import the shared library into the process, thus running its
850 # static (global) initialization code in order to register custom
851 # operators with the JIT.
--> 852 ctypes.CDLL(path)
853 self.loaded_libraries.add(path)

File /usr/lib/python3.8/ctypes/init.py:373, in CDLL.init(self, name, mode, handle, use_errno, use_last_error, winmode)
370 self._FuncPtr = _FuncPtr
372 if handle is None:
--> 373 self._handle = _dlopen(self._name, mode)
374 else:
375 self._handle = handle

OSError: libtorch_cuda_cpp.so: cannot open shared object file: No such file or directory

@rusty1s
Copy link
Member

rusty1s commented Oct 20, 2023

What happens if you run via

pip uninstall torch-sparse
pip install --verbose --no-index torch_sparse -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

@mainguyenanhvu
Copy link

I found the solution here.

@zhangnuc
Copy link

zhangnuc commented Apr 22, 2024

Sooooooo useful to me! @downeykking
I often encounter the same issue with packages such as torch_spline_conv, torch-cluster, torch-sparse, and torch-spline-conv,
which are all related to Torch and CUDA versions.
I solve torch-sparse error with command "pip install torch-sparse==0.6.12 -f https://pytorch-geometric.com/whl/torch-1.9.1+cu111.html" which can instead your cuda version and torch version inthe link "https://pytorch-geometric.com/whl/torch-1.9.1+cu111.html" , also we can solve torch-sparse error by "pip install torch-sparse==0.X.X -f https://pytorch-geometric.com/whl/torch-1.9.1+cu111.html"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants