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

Windows机器安装Ansible报错:module 'os' has no attribute 'get_blocking'

问题描述

在Windows机器上通过pip install ansible命令安装Ansible后,执行Ansible时触发以下报错:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Scripts\ansible.exe\__main__.py", line 4, in <module>
  File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 42, in <module>
    check_blocking_io()
  File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 34, in check_blocking_io
    if not os.get_blocking(fd):
           ^^^^^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'get_blocking'

解决方法

方法1:使用WSL运行Ansible(官方推荐)

  • 启用Windows的WSL功能,安装任意Linux发行版(如Ubuntu)
  • 在WSL的Linux环境内安装Python和pip,执行pip install ansible完成安装,后续所有Ansible操作都在WSL中进行。这种方式能彻底避免Windows原生Python与Ansible的兼容性问题。

方法2:降级Python版本

  • 卸载当前的Python 3.11,安装Python 3.10及以下的稳定版本
  • 重新执行pip install ansible安装,再测试Ansible功能。Windows平台的Python 3.11在os.get_blocking接口上存在兼容性问题,降级后可解决该报错。

方法3:安装兼容的Ansible版本

  • 尝试安装指定版本的Ansible,例如执行pip install ansible==7.7.0
  • 安装完成后运行Ansible,验证报错是否消失。部分旧版Ansible对Windows原生Python的兼容性更好。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 01:20:38