3

I want a program to determine which OS and its version is running on the computer. I was really confused when platform.release() returned '8' since my computer was originally running on windows 8 but I updated on windows 10 several months ago.

My guess would be that it is more of a windows issue than a python problem. Is there a way o fix this? Or should I use a different module than platform?

I am using python 3.4.3. The whole version name platform.platform() returns is 'Windows-8-6.2.9200' but I can't tell whether it is the very first version on the computer or the last one before the Update.

13
  • 3.4.4 python returns "10" on my windows 10 box, and "Windows-10-10.0.14393" (release()) Commented Aug 19, 2017 at 19:59
  • um can you please explain why my answer is wrong? does sys.platform not work? Commented Aug 19, 2017 at 20:01
  • @ Jean-François Fabre: which version of the platform.py file do you have? Commented Aug 19, 2017 at 20:07
  • it's 1.0.7 for python 3.4.4 Commented Aug 19, 2017 at 20:09
  • I have 1.0.7 too. I'm not sure but starting with line 589 there are some if statements and the last one determines 8. there is nothing with 10. Commented Aug 19, 2017 at 20:12

3 Answers 3

3

From the Python Changelog Documentation for 3.4.4-release-candidate-1

bpo-19143: platform module now reads Windows version from kernel32.dll to avoid compatibility shims.

which fixes the referenced bug:

Python is returning incorrect version info under Windows 8.1. ... it appears MS is "deprecating" GetVersionEx()

which references a StackOverflow question.

Sign up to request clarification or add additional context in comments.

Comments

0
import platform
platform.platform()

That gives me the number 10, I assume since I'm running windows 10.

platform.system()

That returns windows.

1 Comment

thanks but I do it the same way just with the wrong outcome of 8
-1

Windows 10 is notorious exactly for this issue, hardship of detecting the true Windows version via previously known API. To make the long story short (sorry if this doesn't sound like a 'quality' answer) one needs either a OS compatibility element in the app manifest, or egregious hacks. Previously known API (GetVersionEx, VerifyVersionInfo) declared deprecated. So, what the Python interpreter gets, depends likely on whether it is built with a suitable manifest.

Recent Python executables have Win10 listed in the manifest (yes, I've checked, on v. 3.6.1) so they can get the correct Win10 version in a normal way... Until Microsoft breaks it again.

5 Comments

The backwards-compatibility behaviour you're talking about was introduced in Windows 8.1. No "egregious hacks" are necessary; there's a documented solution. Python should be doing the right thing by now, and it seems to be working for Jean.
@HarryJohnston - your 'documented solution' link (version helpers) is based on API which is now declared deprecated. Without a proper manifest the 'version helpers' won't work. Recently built Python executables (3.6.1 for example) have the manifest with Win10 compatibility (there are also other reasons to do this - long paths support for one). But if someone has to run old executables on Win10 for some reason - sorry, no luck.
Quoting from my link: "To obtain the full version number for the operating system, call the GetFileVersionInfo function on one of the system DLLs, such as Kernel32.dll, then call VerQueryValue to obtain the \\StringFileInfo\\<lang><codepage>\\ProductVersion subblock of the file version information." That's the correct solution, does not depend on the manifest, and Python does indeed use it. The problem is just that the OP is using a seriously out-of-date version of Python.
On this I completely agree. The OP likely is using an old binary without the proper manifest. Reading the version of kernel32.dll is one of egregious hacks. It is shocking to read advises like this on MSDN, But compared to other woes these days, it's nonsense.
Reading the version number from kernel32.dll isn't a hack, the decision to make that the only supported method (for logging purposes, pretty much the only case when you need the actual version number) was quite deliberate. Whether or not it will work, i.e., persuade programmers to use the helper functions rather than continuing to write their own broken version number checks, I don't know, but it wasn't something that was done gratuitously or carelessly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.