detect windows 8.1 in python?

  • Last Update :
  • Techknowledgy :

The way that I worked around the problem is to use ctypes and a kernel mode function, RtlGetVersion. Despite this being a kernel mode function it can be called from user mode just fine. I've tried this on many versions of Windows and not had an issue.

import ctypes

class OSVERSIONINFOEXW(ctypes.Structure):
   _fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
      ('dwMajorVersion', ctypes.c_ulong),
      ('dwMinorVersion', ctypes.c_ulong),
      ('dwBuildNumber', ctypes.c_ulong),
      ('dwPlatformId', ctypes.c_ulong),
      ('szCSDVersion', ctypes.c_wchar * 128),
      ('wServicePackMajor', ctypes.c_ushort),
      ('wServicePackMinor', ctypes.c_ushort),
      ('wSuiteMask', ctypes.c_ushort),
      ('wProductType', ctypes.c_byte),
      ('wReserved', ctypes.c_byte)

def get_os_version():
Get 's the OS major and minor versions.  Returns a tuple of
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
   raise Exception("Failed to get OS version")

return os_version.dwMajorVersion, os_version.dwMinorVersion

Suggestion : 2

This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide.

This question:

   http: //

   reports that Python is returning incorrect version info under Windows 8.1.

Alas, it appears MS is "deprecating"

http: //

   and replacing it with a whole slew of annoying "yes or no?"

   http: //

   Heh; - )
I was surprised that GetVersionEx would lie.But sure enough.Here:

   http: //

   (Including a heartfelt comment by long - time Python developer Tim Roberts)
I 've just installed a Win 8.1 VM and can (unsurprisingly) confirm the
report: The "ver"
command shows 6.3 .9600
while GetVersionEx and
consequently sys.getwindowsversion report 6.2 .9200

We do use GetVersionEx in a few other places(timemodule.c,
   unicodeobject.c, install.c) but they 're limited to checking that we'
running at least XP or at least Vista which will
continue work as such.

I 'm not really sure what to propose: we could simply sit back and say
"We're telling you what Windows tells us".It 's unappealing, but I'
m not
sure there 's a clear alternative.
platform.platform & platform.uname are also affected although they already use "ver" - parsing in some circumstances so could presumably fallback to that approach here as well.
(One explanation is they did it
   for the enjoyment of non - Windows programmers)
tim.peters: looking at the implementation of the proposed annoying functions with names like IsWindows8Point1OrGreater, it turns out that they all go back to VerifyVersionInfoW, which is available since W2k (but still doesn't tell the actual version).

tim.golden: a work-around is documented in


<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

into the manifest of python.exe, and it should report the correct version. Of course

a) this would fail for somebody embedding Python (unless they have that in their exe's manifest), and
b) we don't know the Id of upcoming windows versions, so the binaries produced today might still lie on future Windows releases.

It seems possible to query the compatibility using QueryActCtxW and CompatibilityInformationInActivationContext, but I couldn't find a way to put the compatibility into a new activation context (which would allow to claim compatibility dynamically).

Suggestion : 3

Install Opencv Python PIP Windows,Following are the steps to download Python executable installer:,pip is a powerful software package management system for Python, so double-check that it is installed.,Inheritance in Python

4. Open the cmd and type py --version. The cmd will show you the Python version of Python installed. Otherwise, it will inform you that your desktop doesn't have Python.

  1. Open a command prompt window.
  2. If you want to check if your desktop has pip, enter pip -V
  3. The following output will appear after installation.
pip - V

2. To check for Pip installation, in the command prompt, type the following command and press enter.