uv 依赖冲突:requires-python 太宽 + Windows 装 triton 的双坑

上一个 CV 项目,uv sync 直接崩:

× No solution found when resolving dependencies for split
  (markers: python_full_version == '3.8.*'):
  ↳ Because the requested Python version (>=3.8) does not satisfy
    Python>=3.9.0 and numpy>=1.26.0 depends on Python>=3.9,<3.13,
    we can conclude that numpy>=1.26.0 cannot be used.

看起来是”numpy 装不上”,其实是 Python 版本范围和依赖范围打架

症状识别:requires-python 太宽

pyproject.toml 里如果写了:

requires-python = ">=3.8"

uv 会尝试为 3.8 / 3.9 / … / 3.12 全部找一套解。numpy ≥ 1.26 要求 Python ≥ 3.9,Python 3.8 直接被排除——solver 认为”你说要支持 3.8,但 3.8 没解”,结论:无解。

解法:收紧 requires-python

改成现代 AI 项目实际支持的范围:

requires-python = ">=3.10,<3.13"

理由:

  • numpy ≥ 1.26 要求 Python ≥ 3.9
  • torch 2.x + Windows 的 wheel 覆盖到 3.12
  • 3.13 太新,很多 native wheel 还没出

之后 uv sync 通常就过了。

另一坑:Windows 上 triton 无解

同一个项目继续装:

uv pip install triton
× No solution found:
  triton<=2.1.0 has no wheels with a matching Python ABI tag (e.g., cp312)
  triton>=2.2.0 has no wheels with a matching platform tag (win_amd64)

不是版本冲突,是 triton 官方根本不出 Windows wheel。Linux 有 manylinux_x86_64,macOS 部分版本有,Windows 是空白。

Windows 上处理 triton 的三条路

方案 A:上 WSL2(推荐)

装个 Ubuntu,在里面:

python3.11 -m venv venv
source venv/bin/activate
pip install triton torch

CUDA、torch、triton 生态齐活。

方案 B:直接放弃 triton

只是跑 inference 或 demo,很多模型不强依赖 triton:

uv remove triton

代码里如果有 import triton,包一层 try/except 或者按平台条件装:

[project.optional-dependencies]
gpu = ["triton; sys_platform == 'linux'"]

方案 C:走 Linux 服务器

有云 GPU 就直接扔上去,从头就没 Windows 这个问题。

uv 常用的调试思路

# 看清依赖树里谁在拉某个包
uv tree | grep numpy

# 只解析不装,快速试冲突
uv lock

# 指定用某个 Python
uv sync --python 3.11

# 显式约束某个包
uv add "numpy>=1.26,<2"

一句话总结

uv 报 no solution,先看两点:requires-python 范围是不是包了依赖不支持的旧 Python、目标平台是不是根本没轮子。Windows 上装 triton 是无解,别死磕。