You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows平台下psutil风扇转速与温度模块替代方案咨询

替代工具推荐(获取风扇转速与硬件温度)

1. OpenHardwareMonitorLib

通过Python调用OpenHardwareMonitor的库可稳定获取硬件温度与风扇数据,步骤如下:

  • 下载OpenHardwareMonitor安装包,找到OpenHardwareMonitorLib.dll文件
  • 安装pythonnet库加载DLL:pip install pythonnet
  • 示例代码:
import clr

# 替换为你的OpenHardwareMonitorLib.dll路径
clr.AddReference(r'C:\Program Files\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')
from OpenHardwareMonitor.Hardware import Computer

def get_hardware_status():
    computer = Computer()
    # 启用需要监控的硬件类型
    computer.CPUEnabled = True
    computer.GPUEnabled = True
    computer.FanControllerEnabled = True
    computer.HDDEnabled = True
    computer.Open()

    for hardware in computer.Hardware:
        hardware.Update()
        print(f"硬件名称: {hardware.Name}")
        for sensor in hardware.Sensors:
            if sensor.SensorType == sensor.SensorType.Temperature:
                print(f"  温度传感器: {sensor.Name} - {sensor.Value}°C")
            elif sensor.SensorType == sensor.SensorType.Fan:
                print(f"  风扇: {sensor.Name} - {sensor.Value} RPM")
        print()

    computer.Close()

if __name__ == "__main__":
    get_hardware_status()

2. PySMBIOS

专注读取系统BIOS信息,部分硬件的温度数据可通过SMBIOS获取:

  • 安装依赖:pip install pysmbios
  • 示例代码:
from smbios import SMBIOS

def get_smbios_temperature():
    smbios = SMBIOS()
    for info in smbios:
        if info.type == 28:  # 匹配温度传感器类型
            print(f"传感器名称: {info.designation}")
            print(f" 当前温度: {info.current_temperature}°C")
            print(f" 阈值温度: {info.threshold}°C")
            print()

if __name__ == "__main__":
    get_smbios_temperature()

局限性:并非所有硬件都支持通过SMBIOS暴露数据,风扇转速大概率无法获取

3. LM Sensors(仅Linux系统)

Linux平台下的老牌硬件监控工具,可直接读取传感器数据:

  • 先安装系统工具包(Debian/Ubuntu):sudo apt install lm-sensors
  • 安装Python库:pip install pysensors
  • 示例代码:
import sensors

def get_linux_hardware_data():
    sensors.init()
    try:
        for chip in sensors.iter_detected_chips():
            print(f"芯片: {chip}")
            for feature in chip:
                if 'temp' in feature.label.lower():
                    print(f"  温度: {feature.label} - {feature.get_value()}°C")
                elif 'fan' in feature.label.lower():
                    print(f"  风扇转速: {feature.label} - {feature.get_value()} RPM")
            print()
    finally:
        sensors.cleanup()

if __name__ == "__main__":
    get_linux_hardware_data()

内容的提问来源于stack exchange,提问作者ItsAllay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 21:12:38