CPUInfo 本身不直接提供温度检测功能,但可通过结合系统工具或库实现。以下是不同系统的常见方法:
Win + R
输入 msinfo32
,查看处理器型号,但无法直接获取温度。lm-sensors
工具
sudo apt-get install lm-sensors
(Debian/Ubuntu)或 sudo yum install lm-sensors
(RHEL/CentOS)。sudo sensors-detect
,按提示操作。sensors
命令输出核心温度,单位为摄氏度。cat /sys/class/thermal/thermal_zone*/temp
,数值需除以 1000 转换为摄氏度。ipmitool
(适用于支持 IPMI 的系统)
sudo apt-get install ipmitool
。sudo ipmitool -I open sdr | grep Temp
。psutil
和 py-cpuinfo
库(需硬件支持),示例代码:import psutil
temps = psutil.sensors_temperatures()
if 'coretemp' in temps:
print(f"CPU温度: {temps['coretemp'][0].current}°C")
注意:部分工具需硬件支持温度传感器,且需以管理员权限运行命令。