[Python] Python: get windows OS version and architecture

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    First of all, I don't think this question is a duplicate of
    Detect 64bit OS (windows) in Python
    because imho it has not been thoroughly answered.

    The only approaching answer is:


    Use sys.getwindowsversion() or the existence of PROGRAMFILES(X86) (if 'PROGRAMFILES(X86)' in os.environ)
    ​

    But:

    • Does the windows environment variable PROGRAMFILES(X86) reliable? I fear that anyone can create it, even if it's not present on the system.
    • How to use sys.getwindowsversion() in order to get the architecture?

    Regarding sys.getwindowsversion():
    The link http://docs.python.org/library/sys.html#sys.getwindowsversion
    leads us to http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx
    but I don't see anything related to the architecture (32bit/64bit).
    Moreover, the platform element in the returned tuple seems to be independent of the architecture.

    One last note: I'm looking for a solution using both python 2.5 and a windows version starting at Windows XP

    Thanks!

    Edit:
    The relevant info is available here
    http://msdn.microsoft.com/en-us/library/ms724340(v=VS.85).aspx
    but how can I get this with python?

    Edit2: On a 64bit windows, with a 32bit python interpreter:

    • os.environ["PROCESSOR_ARCHITECTURE"] returns
      • 'x86'
    • platform.architecture() returns
      • ('32bit', 'WindowsPE')

    Continue reading...

Compartilhe esta Página