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

Linux下Python3.10用Poetry安装ansible-lint遇Windows依赖兼容问题

问题

在搭载Python 3.10的Linux机器上执行poetry add ansible-lint时遭遇依赖解析失败,报错信息如下:

poetry add ansible-lint
Using version ^6.14.2 for ansible-lint

Updating dependencies
Resolving dependencies... (0.2s)

  SolverProblemError

  The current project's Python requirement (>=3.10) is not compatible with some of the required packages Python requirement:
    - will-not-work-on-windows-try-from-wsl-instead requires Python >=3.11,<4.0, so it will not be satisfied for Python >=3.10,<3.11 || >=4.0
  
  Because no versions of ansible-lint match >6.14.2,<7.0.0
   and ansible-lint (6.14.2) depends on will-not-work-on-windows-try-from-wsl-instead (*), ansible-lint (>=6.14.2,<7.0.0) requires will-not-work-on-wsl-instead (*).
  Because will-not-work-on-windows-try-from-wsl-instead (0.1.0) requires Python >=3.11,<4.0
   and no versions of will-not-work-on-wsl-instead match !=0.1.0, will-not-work-on-windows-try-from-wsl-instead is forbidden.
  Thus, ansible-lint is forbidden.
  So, because ansible-lean depends on ansible-lint (^6.14.2), version solving failed.

当前项目的pyproject.toml依赖片段:

[tool.poetry.dependencies]
python = "^3.10"
ansible-core = "^2.14.3"
molecule = "^4.0.4"
black = "^23.1.0"
yamllint = "^1.29.0"
pytest = "^7.2.2"
pytest-testinfra = "^7.0.0"

疑问:操作是否有误?为何Linux环境会出现Windows相关依赖包?

解答

原因分析

  1. 占位包的特殊作用:will-not-work-on-windows-try-from-wsl-instead是ansible-lint维护者发布的“提示型占位包”,目的是阻止ansible-lint在Windows原生环境下安装——因为ansible-lint本身不支持Windows原生系统,只能通过WSL运行。这个包的存在是给Windows用户明确报错提示,而非提供实际功能,所以即使在Linux环境下,ansible-lint的依赖链也会包含它。
  2. 版本兼容性冲突:你指定安装的ansible-lint ^6.14.2版本,刚好引入了这个占位包,而该占位包要求Python >=3.11,但你的项目Python版本限制为^3.10,直接触发依赖解析失败。

解决方法

方法一:降低ansible-lint版本

选择不依赖该占位包的ansible-lint版本(6.14.1及以下):

poetry add ansible-lint@^6.14.1

方法二:升级项目Python版本

将项目Python版本提升至3.11+,修改pyproject.toml中的Python约束:

python = "^3.11"

之后重新执行安装命令:

poetry add ansible-lint

方法三:强制排除依赖(不推荐)

若必须保留Python 3.10且使用ansible-lint 6.14.2+,可尝试通过Poetry强制排除该占位包,但可能引发未知兼容性问题:

poetry add ansible-lint --without will-not-work-on-windows-try-from-wsl-instead

注意:此方法仅作为临时应急方案,可能导致ansible-lint功能异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 05:42:54