简体   繁体   中英

How can I get CPU temperature in Python? Assuming that I have Windows 32-bits

I have tried with psutil library using sensors_temperatures() , but it is giving me an AttributeError. Here is my code:

import psutil
print(psutil.sensors_temperatures())

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-fbefe6006680> in <module>
----> 1 print(psutil.sensors_temperatures())

AttributeError: module 'psutil' has no attribute 'sensors_temperatures'

Moreover, it seems that the function sensors_temperatures() do no longer exist in psutil when I checked it with help(psutil)

Sir you can use simple code for find the CPU temperature using python. And it is not necessary that you should use only 'psutil' for finding the temperature. You can usethe WMI module + Open Hardware Monitor + its WMI interface described here.

import wmi
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
    if sensor.SensorType==u'Temperature':
        print(sensor.Name)
        print(sensor.Value)

# This is a simple code to find the temperature of the CPU using Python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM