pythonwindowswinapicputemperature

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)


Solution

  • 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.