3 回答

TA貢獻1811條經驗 獲得超4個贊
我認為沒有直接的方法可以實現這一目標。一些 CPU 生產商不會wmi
直接讓您知道溫度。
你可以使用OpenHardwareMoniter.dll
. 使用動態庫。
首先,下載OpenHardwareMoniter
. 它包含一個名為OpenHardwareMonitorLib.dll
(版本 0.9.6,2020 年 12 月)的文件。
安裝模塊pythonnet
:
pip install pythonnet
下面的代碼在我的電腦上運行良好(獲取 CPU 溫度):
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()
要獲取 GPU 溫度,請將 更改c.Hardware[0]為c.Hardware[1]。
將結果與:

TA貢獻1820條經驗 獲得超9個贊
所以你可以gpiozero先獲取溫度pip install gpiozero然后from gpiozero import CPUTemperature導入它cpu = CPUTemperature() print(cpu.temperature)
代碼:
from gpiozero import CPUTemperature
cpu = CPUTemperature()
print(cpu.temperature)
希望你喜歡。:)
添加回答
舉報