Torch_sparse can't find nvcc

vhrn: <p>I’m trying to install torch_sparse in my environment with:</p>
<p><code>pip install torch_sparse</code></p>
<p>At first the installation could not find cuda.h, but following this <a href="https://discuss.pytorch.org/t/cuda-h-missing-error-with-torch-compile/171669">topic</a> I’ve set the CUDA_HOME variable to my environment directory. After that I get the error message below (end of message), complaining about not finding nvcc. I’ve searched for my nvcc and its actual address is at the anaconda3 bin dir:<code> /mnt/LINUX_DADOS/anaconda3/bin/nvcc</code></p>
<p>Can/Should I copy the nvcc bin, or should I set another variable before running pip?</p>
<p>I’ve followed the steps in this video to install nvcc, cudatoolkit and pytorch:</p>
<pre><code class="lang-auto">conda install -c nvidia cuda-nvcc
conda install -c anaconda cudatoolkit
conda install pytorch torchvision torchaudio pytorch-cuda -c pytorch -c nvidia
</code></pre>
<p>Thanks in advance,</p>
<blockquote>
<p>Collecting torch_sparse<br>
Using cached torch_sparse-0.6.18.tar.gz (209 kB)<br>
Preparing metadata (setup.py) … done<br>
Requirement already satisfied: scipy in /mnt/LINUX_DADOS/anaconda3/envs/difusco/lib/python3.12/site-packages (from torch_sparse) (1.13.0)<br>
Requirement already satisfied: numpy&lt;2.3,&gt;=1.22.4 in /mnt/LINUX_DADOS/anaconda3/envs/difusco/lib/python3.12/site-packages (from scipy-&gt;torch_sparse) (1.26.4)<br>
Building wheels for collected packages: torch_sparse<br>
Building wheel for torch_sparse (setup.py) … error<br>
error: subprocess-exited-with-error</p>
<p>× python setup.py bdist_wheel did not run successfully.<br>
│ exit code: 1<br>
╰─&gt; [53 lines of output]<br>
running bdist_wheel<br>
running build<br>
running build_py<br>
creating build<br>
creating build/lib.linux-x86_64-cpython-312<br>
creating build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/index_select.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/spmm.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/cat.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/rw.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/convert.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/coalesce.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/bandwidth.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/tensor.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/storage.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/spspmm.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/spadd.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/typing.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/metis.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/saint.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/transpose.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/matmul.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/add.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/utils.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/mul.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/testing.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/masked_select.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/diag.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/reduce.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/permute.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/eye.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/sample.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/select.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/narrow.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
copying torch_sparse/<strong>init</strong>.py → build/lib.linux-x86_64-cpython-312/torch_sparse<br>
running egg_info<br>
writing torch_sparse.egg-info/PKG-INFO<br>
writing dependency_links to torch_sparse.egg-info/dependency_links.txt<br>
writing requirements to torch_sparse.egg-info/requires.txt<br>
writing top-level names to torch_sparse.egg-info/top_level.txt<br>
reading manifest file ‘torch_sparse.egg-info/SOURCES.txt’<br>
reading manifest template ‘MANIFEST.in’<br>
warning: no previously-included files matching ‘<em>’ found under directory ‘third_party/parallel-hashmap/css’<br>
warning: no previously-included files matching '</em>’ found under directory ‘third_party/parallel-hashmap/html’<br>
warning: no previously-included files matching ‘<em>’ found under directory ‘third_party/parallel-hashmap/tests’<br>
warning: no previously-included files matching '</em>’ found under directory ‘third_party/parallel-hashmap/examples’<br>
warning: no previously-included files matching ‘<em>’ found under directory ‘third_party/parallel-hashmap/benchmark’<br>
warning: no previously-included files matching '</em>’ found under directory ‘test’<br>
warning: no previously-included files matching ‘*’ found under directory ‘benchmark’<br>
adding license file ‘LICENSE’<br>
writing manifest file ‘torch_sparse.egg-info/SOURCES.txt’<br>
running build_ext<br>
error: [Errno 2] No such file or directory: ‘/mnt/LINUX_DADOS/anaconda3/envs/difusco/bin/nvcc’<br>
[end of output]</p>
<p>note: This error originates from a subprocess, and is likely not a problem with pip.<br>
ERROR: Failed building wheel for torch_sparse<br>
Running setup.py clean for torch_sparse<br>
Failed to build torch_sparse<br>
ERROR: Could not build wheels for torch_sparse, which is required to install pyproject.toml-based projects</p>
</blockquote>

ptrblck: <p>I would recommend installing a full CUDA toolkit locally, instead of the <code>conda</code> pieces, if you want to build this library from source.</p>

vhrn: <p>Thank you for the reply!</p>
<p>I’ve installed the CUDA toolkit locally, following this [guide](<a href="https://developer.nvidia.com/cuda-downloads?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=Ubuntu&amp;target_version=22.04&amp;target_type=deb_local" class="inline-onebox" rel="noopener nofollow ugc">CUDA Toolkit 12.4 Update 1 Downloads | NVIDIA Developer</a>, and nvcc seems to be working (after I’ve set the cuda bin directory to the path).</p>
<p>I don’t want to build anything from source if I don’t have to. Are you saying I should? In this case, which guide should I follow?</p>

ptrblck: <p>Your command tries to build the library from soure, otherwise <code>nvcc</code> wouldn’t be needed.<br>
<code>pytorch_sparse</code> shows the command to install the binaries in their <a href="https://github.com/rusty1s/pytorch_sparse?tab=readme-ov-file#binaries">README</a>.</p>

vhrn: <p>Thank you,</p>
<p>I’ve installed pytorch_sparse according to the README and it worked.</p>