torch-sparse install, module 'torch' not found even with torch installed
15:41 10 Feb 2025

I am trying to install the dependencies for this repository https://github.com/kvignesh1420/gnn_collapse which specifies package versions that are a few years old. I have installed Python 3.9, created a virtual environment from that installation, and tried to install the packages from requirements.txt.

I am aware that the torch dependency for torch-scatter and torch-sparse needs to be installed sequentially prior to installing these modules. However, while doing so allows torch-scatter to be installed, torch-sparse is still giving me the following error.

After having all other packages in the requirements.txt file successfully installed, I have been getting one of two errors dependent on the version of setuptools installed. This is the one I get when I try to install after upgrading setuptools to the most recent version, if it is helpful to show the other error message I can post that as well:

Collecting torch-sparse==0.6.15
Downloading torch_sparse-0.6.15.tar.gz (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 1.1 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─\> \[17 lines of output\]
Traceback (most recent call last):
File "C:\\Users\\caleb\\Python\\graph_transformer_2.venv\\lib\\site-packages\\pip_vendor\\pyproject_hooks_in_process_in_process.py", line 389, in \
main()
File "C:\\Users\\caleb\\Python\\graph_transformer_2.venv\\lib\\site-packages\\pip_vendor\\pyproject_hooks_in_process_in_process.py", line 373, in main
json_out\["return_val"\] = hook(\*\*hook_input\["kwargs"\])
File "C:\\Users\\caleb\\Python\\graph_transformer_2.venv\\lib\\site-packages\\pip_vendor\\pyproject_hooks_in_process_in_process.py", line 143, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\\Users\\caleb\\AppData\\Local\\Temp\\pip-build-env-jv3dantt\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 334, in get_requires_for_build_wheel
return self.\_get_build_requires(config_settings, requirements=\[\])
File "C:\\Users\\caleb\\AppData\\Local\\Temp\\pip-build-env-jv3dantt\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 304, in \_get_build_requires
self.run_setup()
File "C:\\Users\\caleb\\AppData\\Local\\Temp\\pip-build-env-jv3dantt\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 522, in run_setup  
super().run_setup(setup_script=setup_script)
File "C:\\Users\\caleb\\AppData\\Local\\Temp\\pip-build-env-jv3dantt\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 320, in run_setup  
exec(code, locals())
File "\", line 8, in \
ModuleNotFoundError: No module named 'torch'
\[end of output\]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─\> See above for output.

Additional Outputs:

$ python --version
Python 3.9.0
(.venv) 
$ python -m pip --version
pip 25.0.1 from C:\Users\caleb\Python\graph_transformer_2\.venv\lib\site-packages\pip (python 3.9)
(.venv)
$ pip show torch
Name: torch
Version: 2.6.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3-Clause
Location: c:\users\caleb\python\graph_transformer_2\.venv\lib\site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by: PyGCL
(.venv)

Additionally, I'm running into the same problem outside of the context of these particular versions. In the simpler case of trying to make a fresh environment and only install torch and torch-sparse with the latest versions that torch-sparse appears to support (Python 3.12 and torch 2.5.1) I get the same error. After

pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu124

The command

pip install torch-sparse -f https://data.pyg.org/whl/torch-2.5.1+cu124

gives the same error as above. Is the problem with setuptools?

pytorch pip