Python 3(Linux和Windows)中的CPU温度

2024-04-25 16:36:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望在Python3中获得CPU温度。可以是不同的库,但我需要一个用于Linux&;窗户

psutil.sensors\u温度似乎只适用于Python 2。我还没有找到其他合适的替代品


Tags: 替代品linuxcpu温度python3psutilamp窗户
1条回答
网友
1楼 · 发布于 2024-04-25 16:36:14

您可以使用pip在python3中安装psutil。在Ubuntu上,对于psutil所需的某些头文件,您可能需要python-dev包。您可能还需要使用pip3而不是pip

Python 3.8.3 (default, May 17 2020, 18:15:42) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil             
>>> psutil.sensors_temperatures()
{'nvme': [shwtemp(label='Composite', current=37.85, high=84.85, critical=84.85), shwtemp(label='Sensor 1', current=37.85, high=65261.85, critical=65261.85), shwtemp(label='Sensor 2', current=43.85, high=65261.85, critical=65261.85)], 'k10temp': [shwtemp(label='Tctl', current=55.0, high=None, critical=None), shwtemp(label='Tdie', current=55.0, high=None, critical=None), shwtemp(label='Tccd1', current=39.5, high=None, critical=None)], 'nct6797': [shwtemp(label='SYSTIN', current=42.0, high=80.0, critical=80.0), shwtemp(label='PCH_CPU_TEMP', current=0.0, high=None, critical=None), shwtemp(label='CPUTIN', current=37.0, high=115.0, critical=115.0), shwtemp(label='AUXTIN0', current=38.5, high=115.0, critical=115.0), shwtemp(label='AUXTIN1', current=-128.0, high=None, critical=None), shwtemp(label='AUXTIN2', current=60.0, high=None, critical=None), shwtemp(label='AUXTIN3', current=-3.0, high=None, critical=None), shwtemp(label='SMBUSMASTER 0', current=55.0, high=None, critical=None), shwtemp(label='PCH_CHIP_CPU_MAX_TEMP', current=0.0, high=None, critical=None), shwtemp(label='PCH_CHIP_TEMP', current=0.0, high=None, critical=None)]}
>>> 

您只需导入它,它就可以工作了

相关问题 更多 >