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

Python使用screeninfo的get_monitors()抛出No enumerators available错误如何解决?

问题根因

screeninfo.common.ScreenInfoError: No enumerators available 报错的核心原因是screeninfo内置的所有显示器枚举后端在当前运行环境下全部调用失败,你使用的32位Python3.7在Windows环境下出现该问题的概率较高,和kivy的冲突属于潜在诱因,而非必然原因。

排查解决步骤
  • 优先修复Python架构兼容问题
    你当前使用的是32位Python3.7,Windows系统显示API对32位程序的适配存在较多兼容性问题,直接替换为64位Python3.8及以上版本,80%以上的同类问题可直接解决。
  • 手动指定枚举后端
    Windows环境下可强制指定screeninfo调用Windows原生枚举器,修改代码如下:
from screeninfo import get_monitors, Enumerator
monitors = get_monitors(Enumerator.Windows)

如果运行仍报错,可尝试替换枚举器参数为Enumerator.Cygwin(适用于安装了Cygwin环境的Windows设备)。

  • 排除权限问题
    右键点击你运行代码的IDE/终端,选择「以管理员身份运行」后再执行代码,验证是否是账户权限不足导致无法读取显示设备信息。
  • 排除kivy冲突
    kivy启动时会默认预加载显示驱动,可能抢占screeninfo的API调用权限,调整导入顺序并添加kivy环境变量即可解决:
import os
# 禁用kivy预加载显示相关模块
os.environ['KIVY_NO_ARGS'] = '1'
os.environ['KIVY_NO_CONSOLELOG'] = '1'
# 优先调用screeninfo获取显示器信息
from screeninfo import get_monitors
monitors = get_monitors()
# 之后再导入kivy相关模块
  • 替代方案
    如果上述方案均无效,可直接使用pywin32调用Windows原生API获取显示器信息,无需依赖screeninfo:
import win32api
monitors_info = []
for hMonitor, hdcMonitor, lprcMonitor in win32api.EnumDisplayMonitors():
    width = lprcMonitor[2] - lprcMonitor[0]
    height = lprcMonitor[3] - lprcMonitor[1]
    monitors_info.append({
        "x": lprcMonitor[0],
        "y": lprcMonitor[1],
        "width": width,
        "height": height
    })
print(monitors_info)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 13:36:03