2

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)

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
Samir Ahmane
  • 830
  • 7
  • 22
  • `sensors_temperatures` is only available on Linux: https://github.com/giampaolo/psutil/issues/1271 – dspencer Mar 15 '20 at 11:17
  • Related: https://learn.microsoft.com/de-de/previous-versions/visualstudio/visual-studio-2008/hskdteyh(v=vs.90)?redirectedfrom=MSDN – jizhihaoSAMA Mar 15 '20 at 11:30
  • Check this: https://stackoverflow.com/questions/3262603/accessing-cpu-temperature-in-python Windows system is FUNNY :). Drivers are required - for each type of chipset separately. In Linux, however, just read the port. Linux is more versatile, although there are many distributions than Windows. – s3n0 Mar 15 '20 at 11:48
  • Does this answer your question? [Accessing CPU temperature in python](https://stackoverflow.com/questions/3262603/accessing-cpu-temperature-in-python) – eadmaster Jul 19 '23 at 23:34

1 Answers1

1

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.
KetZoomer
  • 2,701
  • 3
  • 15
  • 43