Repository navigation
platform() is not able to detect windows 11 #89545
Description
Activity
sahsariga111 commented
on Oct 5, 2021 sahsariga111mannequinMannequinAuthorMore actionsI am updated to windows 11 . Now I am trying to write script that will detect is user use windows 11 or windows 10 .
I was using the simplest way as possible:
import platform
print(platform.platform())
The result I got is : Windows-10-10.0.22000-SP0
That is quite correct . The build version is correct ,but the windows version is still not .Reacted by Sohang Chopra- added3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Oct 5, 2021 sahsariga111 commented
on Oct 5, 2021 sahsariga111mannequinMannequinAuthorMore actionsThe
platform.win32_ver() returns same answersahsariga111 commented
on Oct 5, 2021 sahsariga111mannequinMannequinAuthorMore actionsThe bug comes from Microsoft terminal bug : If I type there : ver it will return Microsoft Windows [Version 10.0.22000.194] only one patch is if that will check the build .
so :
info = subprocess.check_output(cmd,
stdin=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
text=True,
shell=True)
if(int(info.strip(".")[2])==22000):
return "Windows [Version 11.0.22000.194]sahsariga111 commented
on Oct 5, 2021 sahsariga111mannequinMannequinAuthorMore actionsdemo.py contains dirty hack that can be used as a fix for some time before microsoft will not fix it.
win32_ver() should be using the internal Windows APIs to figure out the version. I do wonder why those don't return the same version as the "ver" command line tool.
Adding our Windows experts to the noisy list.
The version number for "Windows 11" still starts with 10.0. Just like how Windows 5.x and 6.x were around for a very long time each ;)
There are tables in platform module that map the specific version to the release name. These probably need to be updated to return "11" for versions 10.0.22000 and greater.
On 05.10.2021 22:30, Steve Dower wrote:
The version number for "Windows 11" still starts with 10.0. Just like how Windows 5.x and 6.x were around for a very long time each ;)
There are tables in platform module that map the specific version to the release name. These probably need to be updated to return "11" for versions 10.0.22000 and greater.
Hmm, but the "ver" output seems to have more information than those
APIs.Note: The tables for mapping to releases for Windows only take the
major.minor versions as key. Unfortunately, those did not change. It's
actually the build version which provides the indicator, it seems.Any idea, whether a patch will fix this on Windows soonish ?
The _WIN32_CLIENT_RELEASES table based on major.minor version number isn't helpful since Windows 10 and 11 have the same version number. win32_ver() needs a workaround to return release "11" if the build number is 22000 or greater. Is there any need/desire to also identify Server 2016, 2019, and 2022?
Hmm, but the "ver" output seems to have more information than those APIs.
It's always had build numbers, which the regular APIs do not, because the regular APIs are meant for detecting incompatibilities rather than reporting.
Since there are some incompatibilities, I hope they'll rev the minor version number, but I have no idea if that's planned yet. In theory I have early access to the release build already, but I haven't installed it on anything.
Eventually I think we're going to need some kind of WMI call in the platform module to get the right data for reporting. Until then, we're making best guesses from heuristics.
sahsariga111 commented
on Oct 7, 2021 sahsariga111mannequinMannequinAuthorMore actionssysteminfo can be option
It's probably time to extend the marketing version detection mechanism to use
the build number as reference instead of the major.minor system version numbers.Here's a good reference for this:
https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
MS resources:
https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
https://docs.microsoft.com/en-us/windows/release-health/release-information42 remaining items
The fix for this (not including
getwindowsversion()) has been merged for 3.12, but should probably be considered for 3.11 and 3.10 as well.I don't think it's important enough to hold up 3.11.0, so we'd be looking at 3.11.1. And we just missed 3.10.7, so no rush for 3.10.8. But I'll leave this open until the backports are done.
Because of the side effects of the calling the _wmi module, I would prefer to only target Python 3.12. I would prefer to get more feedback to see if everything goes well. It's too late to add new feateures to Python 3.11.
The workaround on older Python versions is to run the
vercommand, as done by test.pythoninfo: see collect_windows().Fair enough, consider this closed.
Thanks for fixing this issue, it's good to have an easy way to retrieve the real Windows version ;-)
Maybe _wmi can be used for other purposed later. Maybe we can expose it somehow later.
Reacted by Steve DowerWhy shell out or use _wmi rather than the registry HKLM\software\Microsoft\windows nt\CurrentVersion ProductName
Because the registry key is unsupported and primarily for compatibility reasons.
Also, for example, the value of
ProductNameon my Windows 11 machine is "Windows 10 Enterprise", which is exactly the bug we were trying to fix here.The
platformmodule is intended to get true information, not compatibility shims.Reacted by Mr Beedell, Roke Julian Lockhart- added a commit that references this issue
on Oct 28, 2024 - added a commit that references this issue
on Apr 1, 2026 - added a commit that references this issue
on May 1, 2026
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: