如何使用uv安装pytorch

相关:

https://hellowac.github.io/uv-zh-cn/guides/integration/pytorch/




编写pyproject.toml 文件


内容:


[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12.0"
dependencies = [
  "torch>=2.5.1",
  "torchvision>=0.20.1",
]

[tool.uv.sources]
torch = [
  { index = "pytorch-cpu", marker = "platform_system == 'Windows'" },
  { index = "pytorch-cu124", marker = "platform_system == 'Linux'" },
]
torchvision = [
  { index = "pytorch-cpu", marker = "platform_system == 'Windows'" },
  { index = "pytorch-cu124", marker = "platform_system == 'Linux'" },
]

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true




CPU版本安装:

uv sync --extra cpu




GPU版本安装:

uv sync --extra cu124





posted on 2026-07-02 20:45  Angry_Panda  阅读(2)  评论(0)    收藏  举报

导航