How to Get the CPU Temperature

How can I get the CPU temperature?

I'm pretty sure it's manufacturer dependent, since they will be accessed through an I/O port. If you have a specific board you're trying to work with, try looking through the manuals and/or contacting the manufacturer.

If you want to do this for a lot of different boards, I'd recommend contacting someone at something like SiSoftware or be prepared to read a lot of motherboard manuals.

As another note, not all boards have temperature monitors.

You also might run into problems getting privileged access from the kernel.

How can we get a CPU temperature through WMI?

Namespace: root\wmi
Path: MSAcpi_ThermalZoneTemperature

To run this (using wmic) from the Windows command line (cmd.exe) the command would be:

wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint, CurrentTemperature

Attention: the results are in Kelvin * 10, so you need to divide the result by 10, and then subtract 273.15 to get °Celsius.


More information:

  • WUtils.com : MSAcpi_ThermalZoneTemperature Properties

  • Wikipedia : Kelvin (and conversion to/from °C and °F)

  • Wikipedia : Windows Management Instrumentation (WMI)
  • MSDN : WMI Command Line (WMIC)
  • Tech Advisor : What's the Best CPU Temperature?
  • SpeedFan : Fan & Temperature control utility (Freeware)
  • systeminformation: systeminformation npm package (for nodejs)

Get CPU and GPU Temp using Python Windows

I think there doesn't have a directly way to achieve that. Some CPU producers wouldn't provide wmi to let your know the temperature directly.

You could use OpenHardwareMoniter.dll. Use the dynamic library.

Firstly, Download the OpenHardwareMoniter. It contains a file called OpenHardwareMonitorLib.dll (version 0.9.6, December 2020).

Install the module pythonnet:

pip install pythonnet

Below code works fine on my PC (Get the CPU temperature):

import clr # the pythonnet module.
clr.AddReference(r'YourdllPath')
# e.g. clr.AddReference(r'OpenHardwareMonitor/OpenHardwareMonitorLib'), without .dll

from OpenHardwareMonitor.Hardware import Computer

c = Computer()
c.CPUEnabled = True # get the Info about CPU
c.GPUEnabled = True # get the Info about GPU
c.Open()
while True:
for a in range(0, len(c.Hardware[0].Sensors)):
# print(c.Hardware[0].Sensors[a].Identifier)
if "/temperature" in str(c.Hardware[0].Sensors[a].Identifier):
print(c.Hardware[0].Sensors[a].get_Value())
c.Hardware[0].Update()

To Get the GPU temperature, change the c.Hardware[0] to c.Hardware[1].

Compare the result with :

Sample Image

Sample Image

Attention: If you want to get the CPU temperature, you need to run it as Administrator. If not, you will only get the value of Load. For GPU temperature, it can work without Admin permissions (as on Windows 10 21H1).

I did some changes from a Chinese Blog

NodeJS get CPU temperature - Use OpenHardwareMonitorLib.dll in NodeJS

You won't be able to get the CPU temp through WMI or any other means accurately. The CPU Driver which keeps the temp is only available through the vendor. Most motherboards have access to the CPU disabled while others have them enabled.

Long story short, the library you are asking about is not an accurate alternative. They have manually built in each motherboard and the available CPU device driver to gain the accuracy. The motherboards that do not allow access is pretty much inaccessible and not accurate.

Most of the CPU temps are on a wing it basis. They use a math formula to simulate what it could be. Then it's still off by a factor of 2 to 3 degrees.

The error you have is basically saying your motherboard doesn't have access to the temp.

This is a motherboard vendor issue with is it available. I went through this 5 years ago and called ASUS Motherboard and found all this out.

CPU temperature real time with python default libraries

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 !



Related Topics



Leave a reply



Submit