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_MAJOR, OS_MINOR). "" " os_version = OSVERSIONINFOEXW() 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
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: //stackoverflow.com/questions/19128219/detect-windows-8-1-in-python
reports that Python is returning incorrect version info under Windows 8.1.
Alas, it appears MS is "deprecating"
`GetVersionEx()`:
http: //msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx
and replacing it with a whole slew of annoying "yes or no?"
functions:
http: //msdn.microsoft.com/en-us/library/windows/desktop/dn424972(v=vs.85).aspx
Heh; - )
I was surprised that GetVersionEx would lie.But sure enough.Here:
http: //social.msdn.microsoft.com/Forums/windowsdesktop/en-US/c471de52-611f-435d-ab44-56064e5fd7d5/windows-81-preview-getversionex-reports-629200
(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' re 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
http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
Put
<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).
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.
py--version
- Open a command prompt window.
- If you want to check if your desktop has pip, enter pip -V
- 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.
pip--version