Windows OS detection
dew-64cores-99c2c0ed | os: Windows 10; ram: 32597MiB; gcc: 11.2.0; arch: 64bit VNNI BMI2 AVX2 SSE41 SSSE3 SSE2 POPCNT
Just it's Windows 2019 Server as well..
dew-7cores-257f6ede | os: Windows 10; ram: 8191MiB; gcc: 11.2.0; python: 3.9.7; worker: 143; arch: 64bit SSSE3 SSE2
This is Windows 11
import platform
def get_os():
uname = platform.uname()
system = uname.system
release = uname.release
version = uname.version
if system == "Windows" and int(version.split(".")[2]) >= 22000:
release = "11"
return system + " " + release
def main():
print(get_os())
if __name__ == "__main__":
main()
Outputs
Linux: Linux 4.19.0-17-amd64
Windows 10: Windows 10
Windows 11: Windows 11
https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version
| Operating system | Version number |
|---|---|
| Windows 11 | 10.0* |
| Windows 10 | 10.0* |
| Windows Server 2022 | 10.0* |
| Windows Server 2019 | 10.0* |
| Windows Server 2016 | 10.0* |
What about platform.platform() (I don't know what it returns on windows)?
Or perhaps platform.platform(aliased=1)?
what it returns on windows
Windows 11: Windows-10-10.0.22000-SP0
what it returns on windows
Windows 11:
Windows-10-10.0.22000-SP0
Hmm weird.
Still not a resolved issue ig https://github.com/python/cpython/issues/89545
The information is useful for debug too, so I will prefer to have the complete information without processing by our side.
- Windows 11 Insider Preview:
print(platform.platform())
Windows-10-10.0.25174-SP0
print(platform.uname())
uname_result(system='Windows', node='cc-wrk-00', release='10', version='10.0.25174', machine='AMD64'
- Windows Server 2022:
print(platform.platform())
Windows-10-10.0.20344-SP0
print(platform.uname())
uname_result(system='Windows', node='WIN-VTORSP9BI0N', release='10', version='10.0.20344', machine='AMD64')
- Windows Server 2019:
print(platform.platform())
Windows-10-10.0.17763-SP0
print(platform.uname())
uname_result(system='Windows', node='WIN-MEN1DKQ4M24', release='10', version='10.0.17763', machine='AMD64')