Search code examples
pythonsensorstemperature

CPU temperature real time with python default libraries


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


Solution

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