在電腦使用過程中,,為了獲取基本配置以及內(nèi)存使用等的操作情況,,需要手動的查看或打開任務(wù)管理器來查看。
為了能夠在查看這些信息時比較方便,,于是使用python做了一個簡易的exe桌面應(yīng)用。在需要時雙擊打開即可隨時獲取這些信息,。
以下應(yīng)用的開發(fā)主要使用了loguru/wmi/psutil三個主要的python非標(biāo)準(zhǔn)庫,,可以選擇使用pip的方式進(jìn)行安裝。
pip install loguru
pip install wmi
pip install psutil
然后,,將需要的模塊全部導(dǎo)入進(jìn)來,,下面的英文注釋都是使用Pycharm AI插件自動生成的。
# It's a logger.
from loguru import logger
# It's a Python module that allows you to connect to Windows Management Instrumentation (WMI) and query system
# information.
import wmi
# It's a Python module that allows you to connect to Windows Management Instrumentation (WMI) and query system
# information.
import psutil as pt
1. 使用python非標(biāo)準(zhǔn)庫wmi獲取電腦三大配置的主要信息,,直接打印出來,。
logger.info('電腦基本配置信息!??!')
pc_ = wmi.WMI()
os_info = pc_.Win32_OperatingSystem()[0]
processor = pc_.Win32_Processor()[0]
gpu = pc_.Win32_VideoController()[0]
os_name = os_info.Name.encode('utf-8').split(b'|')[0]
ram = float(os_info.TotalVisibleMemorySize) / 1024 / 1024
logger.info('操作系統(tǒng)信息:{}'.format(os_name))
logger.info('CPU信息:{}'.format(processor.Name))
logger.info('系統(tǒng)運(yùn)行內(nèi)存:{} GB'.format(ram))
logger.info('顯卡信息:{}'.format(gpu.Name))
2. 使用python非標(biāo)準(zhǔn)庫psutil模塊獲取CPU/內(nèi)存/磁盤等信息,直接打印出來,。
logger.info('電腦使用過程信息?。?!')
memory_info = pt.virtual_memory()
logger.info('電腦運(yùn)行內(nèi)存總大?。簕} GB'.format(round(float(memory_info.total / 1024 / 1024 / 1024), 2)))
logger.info('電腦已使用內(nèi)存大小:{} GB'.format(round(float(memory_info.used / 1024 / 1024 / 1024), 2)))
logger.info('電腦空閑內(nèi)存大?。簕} GB'.format(round(float(memory_info.free / 1024 / 1024 / 1024), 2)))
logger.info('cpu核數(shù):{}'.format(pt.cpu_count()))
disk_usage = pt.disk_usage('/')
logger.info('磁盤總空間:{} GB'.format(round(float(disk_usage.total / 1024 / 1024 / 1024), 2)))
logger.info('磁盤已使用空間:{} GB'.format(round(float(disk_usage.used / 1024 / 1024 / 1024), 2)))
logger.info('磁盤可用空間:{} GB'.format(round(float(disk_usage.free / 1024 / 1024 / 1024), 2)))
「Python 集中營」,,只做知識分享 !