Find out computer specifications with python

Asked 2 years ago, Updated 2 years ago, 120 views

I want to find out the specifications of the computer with Python. For example,

May I know how?

python cpu ram computer

2022-09-22 20:18

1 Answers

The number of cpu, the type of cpu, and the amount of ram are covered by the default library, but more detailed system information may require the use of the native library.

Check the platform module. https://docs.python.org/3/library/platform.html

See also psutil module. https://github.com/giampaolo/psutil

import platform

platform.machine()
Out[3]: 'x86_64'

platform.version()
Out[4]: '#99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017'

platform.platform()
Out[5]: 'Linux-4.4.0-78-generic-x86_64-with-LinuxMint-18.1-serena'

platform.uname()
Out[6]: uname_result(system='Linux', node='allinux-note', release='4.4.0-78-generic', version='#99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017', machine='x86_64', processor='x86_64')

platform.system()
Out[7]: 'Linux'

platform.processor()
Out[8]: 'x86_64'

import os

print(str(os.popen('free -t -m').readlines()))
['              total        used        free      shared  buff/cache   available\n', 'Mem:           7901        1128        4534         409        2239        6017\n', 'Swap:          9535           0        9535\n', 'Total:        17437        1128       14070\n']


2022-09-22 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.