0

How can I detect CPU temperature and RAM temperature in real time with python default libraries?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • AFAIK, there aren't any standard library modules that can interact with the hardware sensors. Would you consider something like `os.system('sensors -uA')` as a solution? Why are you specifically asking about default libraries anyway? – wjandrea Feb 19 '22 at 18:22
  • Possible duplicates: [Getting CPU temperature using Python?](/q/2440511/4518341) (focused on Linux), [Accessing CPU temperature in python](/q/3262603/4518341) (focused on Windows), [Get CPU and GPU Temp using Python Windows](/q/62617789/4518341) – wjandrea Feb 19 '22 at 18:26
  • Thanks for esplicative links... I had already read programs in links... I had tryed check CPU temperature with the following methods: import wmi and import clr but in the same case i had an error in debug... I wanted to go through internal libraries – Marco Battisti Penta Feb 19 '22 at 18:53

1 Answers1

3

I'm not sure that such kind of function or module is standard.

You can install the package psutil to use this function (pip install --user psutil):

import psutil

psutil.sensors_temperatures() 

Otherwise,if you really don't want to install non standard packages, you might find information somwhere on your computer, for example on Linux:

$ cat /sys/class/thermal/thermal_zone*/temp

You can read those kind of files directly in your Python code but I don't think that's a good practice as it's not cross platform !

Félix Herbinet
  • 257
  • 1
  • 8