How to get the system info with Python?

prosseek picture prosseek · Jun 23, 2010 · Viewed 101.1k times · Source

I need to get the info under what environment the software is running. Does python have a library for this purpose?

I want to know the following info.

  • OS name/version
  • Name of the CPU, clock speed
  • Number of CPU core
  • Size of memory

Answer

SilentGhost picture SilentGhost · Jun 23, 2010

some of these could be obtained from the platform module:

>>> import platform
>>> platform.machine()
'x86'
>>> platform.version()
'5.1.2600'
>>> platform.platform()
'Windows-XP-5.1.2600-SP2'
>>> platform.uname()
('Windows', 'name', 'XP', '5.1.2600', 'x86', 'x86 Family 6 Model 15 Stepping 6, GenuineIntel')
>>> platform.system()
'Windows'
>>> platform.processor()
'x86 Family 6 Model 15 Stepping 6, GenuineIntel'