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:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-10-05.19:43:57.181>labels= ['library', '3.10']
title='platform() is not able to detect windows 11'updated_at=<Date2022-03-28.07:10:50.170>user='https://bugs.python.org/sahsariga111'
I 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 .
The 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
sahsariga111mannequin
MannequinAuthor
More actions
demo.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.
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.
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.
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.
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 ver command, as done by test.pythoninfo: see collect_windows().
Activity
sahsariga111 commented on Oct 5, 2021
I 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 .
sahsariga111 commented on Oct 5, 2021
The
platform.win32_ver() returns same answer
sahsariga111 commented on Oct 5, 2021
The 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
demo.py contains dirty hack that can be used as a fix for some time before microsoft will not fix it.
malemburg commented on Oct 5, 2021
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.
zooba commented on Oct 5, 2021
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.
malemburg commented on Oct 5, 2021
On 05.10.2021 22:30, Steve Dower wrote:
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 ?
eryksun commented on Oct 5, 2021
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?
zooba commented on Oct 5, 2021
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
systeminfo can be option
malemburg commented on Oct 7, 2021
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-information
42 remaining items
Merge remote-tracking branch 'cpython/main' into pythongh-89545
Merge branch 'main' into pythongh-89545
gh-89545: Updates platform module to use new internal _wmi module on …
zooba commented on Sep 7, 2022
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.
vstinner commented on Sep 7, 2022
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 ver command, as done by test.pythoninfo: see collect_windows().
zooba commented on Sep 7, 2022
Fair enough, consider this closed.
vstinner commented on Sep 8, 2022
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.
v-python commented on Feb 11, 2023
Why shell out or use _wmi rather than the registry HKLM\software\Microsoft\windows nt\CurrentVersion ProductName
zooba commented on Feb 13, 2023
Because the registry key is unsupported and primarily for compatibility reasons.
Also, for example, the value of ProductName on my Windows 11 machine is "Windows 10 Enterprise", which is exactly the bug we were trying to fix here.
The platform module is intended to get true information, not compatibility shims.
Regenerate known_stdlibs.rs with stdlibs 2024.10.25 (#13963)
Support WindowsRTTTSFilePlayer on Windows 11 (#4512)
Regenerate known_stdlibs.rs with stdlibs 2024.10.25 (#13963)