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

为何Poetry在macOS/Linux上安装Windows专属依赖?如何正确配置?

问题原因

你所使用的配置逻辑符合PEP 508规范,但存在两个问题导致规则不生效:

  1. platform = "windows"是Poetry已废弃的非标准语法,本身不具备跨版本兼容性;
  2. Poetry 1.2及更早版本存在已知缺陷:对直接指定URL的依赖,环境标记(markers)不会生效,平台过滤规则被忽略,会强制尝试安装对应包。
可行解决方案

方案1:升级Poetry到1.3及以上版本(最推荐)

Poetry 1.3版本修复了URL依赖的标记解析问题,使用如下标准写法即可实现仅Windows平台安装torch:

[tool.poetry.dependencies]
# 需明确Python版本约束,当前torch包仅适配Python 3.6
python = "^3.6"
torch = { url = "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp36-cp36m-win_amd64.whl", markers = "sys_platform == 'win32'" }

方案2:使用环境组适配旧版Poetry

如果不能升级Poetry版本,可以将Windows专属依赖放在独立的环境组中:

  1. 在pyproject.toml中新增如下配置:
[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.group.windows.dependencies]
torch = { url = "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp36-cp36m-win_amd64.whl" }
  1. 安装依赖时区分平台执行命令:
  • Windows系统执行:poetry install --with windows
  • macOS、Linux系统执行:poetry install
    此时非Windows平台不会拉取Windows专属的torch包。

内容的提问来源于stack exchange,提问作者conner.xyz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 09:24:03