在Windows上的python中获取CPU温度 [英] Get CPU temperature in python on windows

查看:2990
本文介绍了在Windows上的python中获取CPU温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想在python中读取cpu温度。请以通俗易懂的方式进行解释,因为我以前从未在Windows上执行过此操作,也不必与wmi一起工作。

Basically i want to read the cpu temperature in python. Please explain in layman's terms as i have never done this on windows before nor have i had to work with wmi.

这是我目前所拥有的:

import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature

(我从该线程获取此代码:在python中访问CPU温度

(i got this code from this thread: Accessing CPU temperature in python)

但是,在运行脚本时,出现此错误:

however, on running the script, i get this error:

Traceback (most recent call last):
  File "C:\Users\Ryan\Desktop\SerialSystemMonitor", line 4, in <module>
    temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
  File "C:\Python27\lib\site-packages\wmi.py", line 819, in query
    handle_com_error ()
  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
    raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>

我该怎么做才能使其正常工作?

what can i do to get this to work?

推荐答案

根据 WMI错误常量,您收到的错误是:

According to the MSDN page on WMI Error Constants, the error you have received is:


WBEM_E_NOT_SUPPORTED

2147749900(0x8004100C)

WBEM_E_NOT_SUPPORTED
2147749900 (0x8004100C)

不支持功能或操作。

大概,那么您的CPU不会通过WMI提供温度信息。如果您的CPU没有公开这些信息,那么您可能很不走运,至少就Python的简单解决方案而言。

Presumably, then, your CPU does not provide temperature information through WMI. If your CPU doesn't expose this information, you're probably out of luck, at least as far as a straightforward solution in Python goes.

我认为您已经尝试了另一种选择使用 Win32_TemperatureProbe()在链接的答案中给出;如果您还没有,请尝试一下。

I assume you've tried the other option given in the answer you linked, using Win32_TemperatureProbe(); if you haven't, try it.

这篇关于在Windows上的python中获取CPU温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆