Python: get windows OS version and architecture Python: get windows OS version and architecture windows windows

Python: get windows OS version and architecture


I think the platform module is really the best way to get this info.

  >>> import platform  >>> platform.platform()  'Windows-7-6.1.7601-SP1'  platform.processor()  'Intel64 Family 6 Model 42 Stepping 7, GenuineIntel'

I don't see where to get a firm answer on 32/64 bit windows from here, so I suggest this:

  try:      os.environ["PROGRAMFILES(X86)"]      bits = 64  except:      bits = 32  print "Win{0}".format(bits)

or, if you need to know which flavor of Python you are running (as you can run x32 python under x64 Windows):

x32 python x64 windows:>>> platform.architecture()('32bit', 'WindowsPE')>>> sys.version'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'x64 python x64 windows:>>> platform.architecture()('64bit', 'WindowsPE')>>> sys.version'2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)]'


These variables show your current runtime status on windows:

@rem Test environment using this table:@rem@rem Environment Variable       32bit Native    64bit Native    WOW64@rem PROCESSOR_ARCHITECTURE     x86             AMD64           x86@rem PROCESSOR_ARCHITEW6432     undefined       undefined       AMD64@rem


1 Another option (poll WMI for OsArchitecture):

If you install pywin32 and the python wmi module on top you should be able to do (but only from Windows Vista and up!):

import wmic = wmi.WMI()for os in c.Win32_OperatingSystem():    print os.osarchitecture

2 Alternatively you could also use the _winreg module to check for the existence of SOFTWARE\Wow6432Node under HKEY_LOCAL_MACHINE (this is supposedly only there on 64 bit- OS versions) (no external dependencies).