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

如何将--find-links URL添加至pyproject.toml依赖及解决安装错误?

解决JAX GPU/TPU依赖安装问题及pyproject.toml配置优化

问题背景

当前pyproject.toml配置下,执行pip install -e .可正常安装基础依赖,但安装GPU/TPU可选依赖时出现报错:

  • GPU环境:pip install -e "[gpu]"触发ResolutionImpossible错误
  • TPU环境:pip install -e "[tpu]"提示依赖包不在PyPI索引的错误

解决方案

1. 配置find-links自动查找JAX专属依赖

在pyproject.toml中添加[tool.pip.find-links]节点,指定JAX GPU/TPU依赖的包源链接,让pip能找到PyPI之外的专属包:

[build-system]
requires = ["setuptools>=67.6.0"]
build-backend = "setuptools.build_meta"

[project]
name = "minimal_example"
version = '0.0.1'
requires-python = ">=3.9"

dependencies = [
    "seqio-nightly[gcp,cache-tasks]",
    "t5[gcp]"
]

[project.optional-dependencies]
cpu = ["jax[cpu]", "t5x @ git+https://github.com/google-research/t5x.git"]
gpu = [
    "jax[cuda]",
    "t5x[gpu] @ git+https://github.com/google-research/t5x.git"
]
tpu = [
    "jax[tpu]",
    "t5x[tpu] @ git+https://github.com/google-research/t5x.git"
]
dev = ["pytest", "mkdocs"]

[tool.pip.find-links]
cuda = "https://storage.googleapis.com/jax-releases/jax_cuda_releases.html"
libtpu = "https://storage.googleapis.com/jax-releases/libtpu_releases.html"

2. 修复GPU环境的依赖冲突

原配置中基础依赖已声明t5x,GPU可选依赖又重复声明带[gpu]变体的t5x,导致pip无法解析重复依赖。解决方式是:

  • 把基础依赖中的t5x移除,将其移到cpu可选依赖中,让不同环境的t5x变体独立声明,避免版本冲突。

3. 修复TPU环境的包找不到问题

TPU环境下JAX依赖的libtpu-nightly不在PyPI官方索引,通过上述[tool.pip.find-links]配置的libtpu链接,pip会自动从该地址查找并安装这个包,解决报错。

验证安装

修改配置后,执行对应环境的安装命令即可正常完成安装:

  • CPU环境:pip install -e "[cpu]"
  • GPU环境:pip install -e "[gpu]"
  • TPU环境:pip install -e "[tpu]"
  • 开发环境:pip install -e "[dev]"

内容的提问来源于stack exchange,提问作者BioGeek

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 04:05:33