我查看了这个线程 - Accessing CPU temperature in python - 并且能够让脚本在我的机器上运行,但它似乎只在 OpenHardwareMonitor 可执行文件运行时按预期运行。
那是因为我需要在与可执行文件所在的目录相同的目录中运行脚本吗?到目前为止,我运行脚本的目录似乎没有什么区别。
这是我的脚本版本:
## Purpose of Script is to use WMI and OpenHardWareMonitor to
## get
## CPU temperatures
## Reference:
## https://stackoverflow.com/questions/3262603/accessing-cpu-
## temperature-in-python/32840852#32840852
## Requirements:
##
## WMI Module - https://pypi.org/project/WMI/
## OpenHardwareMonitor -
## https://openhardwaremonitor.org/downloads/
## Seems that the OpenHardWareMonitor executable needs to be
## running
## for the script to run
## This script uses Py3.10
## Must run with interpreter 3.10 for module to be recognized
import wmi
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
if sensor.SensorType==u'Temperature':
print(sensor.Name)
print(sensor.Value)
## Known issues so far
##
## Script doesn't run unless OpenHardWareMonitor executable is
## running.