You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

tox未正确加载构建依赖torch,导致torch-sparse构建失败求助

tox未正确加载构建依赖torch,导致torch-sparse构建失败求助

我最近在项目里用tox的时候碰到了个棘手问题:项目里有些依赖必须先装torch才能正常完成安装,我试着把torch加到构建依赖里,但还是失败了,想请大家帮忙分析下原因!

我的项目配置

tox.ini 文件内容

[tox]
minversion = 4.23.2
envlist = lint
isolated_build = true

[gh-actions]
python =
    3.12: lint

[testenv:{lint}]
commands =
    lint: flake8 src tests

pyproject.toml 文件内容

[build-system]
requires = ["setuptools>=42.0,<78.0", "wheel", "torch==2.5.0"]
build-backend = "setuptools.build_meta"

setup.cfg 文件内容

[options]
packages =
    gnnconcepts
install_requires =
    numpy==2.2.3
    jaxtyping==0.2.36
    wandb>=0.19.3
    tqdm>=4.67.1
    rdkit==2024.9.5
    pandas>=2.2.3
    plotly==5.24.1
    graphium==2.4.7
    scipy==1.13.1
python_requires = >=3.12
package_dir =
    =src
zip_safe = no

运行情况及报错信息

我执行了命令 tox --recreate --verbose,控制台输出看起来显示构建依赖已经在安装了:

.pkg: install_requires> python -I -m pip install setuptools<78.0,>=42.0 torch==2.5.0 wheel
.pkg: exit 0 (31.11 seconds) [PATH TO MY PROJECT]> python -I -m pip install setuptools<78.0,>=42.0 torch==2.5.0 wheel pid=8968

不过紧接着安装项目依赖的时候就失败了,错误信息如下:

lint: install_package_deps> python -I -m pip install graphium==2.4.7 jaxtyping==0.2.36 numpy==2.2.3 pandas>=2.2.3 plotly==5.24.1 rdkit==2024.9.5 scipy==1.13.1 tqdm>=4.67.1 wandb>=0.19.3

[...]

Collecting torch-sparse>=0.6 (from graphium==2.4.7)
  Using cached torch_sparse-0.6.18.tar.gz (209 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error

  Getting requirements to build wheel did not run successfully.
  exit code: 1

  [20 lines of output]
  Traceback (most recent call last):
    File "C:\Users\jonas\Programmieren\gnn-concepts\.tox\lint\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
      main()
    File "C:\Users\jonas\Programmieren\gnn-concepts\.tox\lint\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\jonas\Programmieren\gnn-concepts\.tox\lint\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\jonas\AppData\Local\Temp\pip-build-env-a4iygx15\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\jonas\AppData\Local\Temp\pip-build-env-a4iygx15\overlay\Lib\site-packages\setuptools\build_meta.py", line 304, in _get_build_requires
      self.run_setup()
    File "C:\Users\jonas\AppData\Local\Temp\pip-build-env-a4iygx15\overlay\Lib\site-packages\setuptools\build_meta.py", line 522, in run_setup
      super().run_setup(setup_script=setup_script)
    File "C:\Users\jonas\AppData\Local\Temp\pip-build-env-a4iygx15\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in run_setup
      exec(code, locals())
    File "<string>", line 8, in <module>
  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

另外我注意到,控制台显示torch只用了30秒就安装完成了,这感觉快得有点离谱,虽然可能是有缓存,但我不确定是不是这个导致的问题。我也找过类似的问题,但都没解决我的困惑,希望大家能给点建议!

备注:内容来源于stack exchange,提问作者Jonas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 19:50:26