Why is platform.platform giving a different result on the same system?

I have two versions of my program. The older one is running python 3.7 and the newer one is running python 3.9.

This is what the value of platform.platfrom is in both versions:
Old: Windows-10-10.0.19041-SP0
New: Windows-10-10.0.19044-SP0

The windows version didn’t change. I can reproduce this several times.

Why is there a difference?
The docs don’t give any clue.

Probably because you are using two different versions of Windows?

The one running in Python 3.7 could be Windows-10-10.0.19041-SP0, and the newer one running in Python 3.9 may be on a different machine running Windows-10-10.0.19044-SP0?

If that is not the case, you need to:

  1. check the actual Windows version on both(?) machines – sorry I don’t know how to do that, I don’t use Windows very often;
  2. on both(?) machines, run this minimal script:
import platform
import sys
print(platform.platform(), sys.version, sys.platform)

Copy and paste the exact output of that script into your response. Please do not use a screen shot, photo or other image.

It really is on the same version of Windows:

C:\> ver

Microsoft Windows [Version 10.0.19044.2006]

C:\> py -3.10
Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from platform import platform, win32_ver
>>> platform()
'Windows-10-10.0.19044-SP0'
>>> win32_ver()
('10', '10.0.19044', 'SP0', 'Multiprocessor Free')
>>> from sys import getwindowsversion
>>> getwindowsversion()
sys.getwindowsversion(major=10, minor=0, build=19044, platform=2, service_pack='')
>>> getwindowsversion().build
19044
>>> getwindowsversion().platform_version
(10, 0, 19041)
>>> exit()

C:\> py -3.9
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from platform import platform, win32_ver
>>> platform()
'Windows-10-10.0.19041-SP0'
>>> win32_ver()
('10', '10.0.19041', 'SP0', 'Multiprocessor Free')
>>> from sys import getwindowsversion
>>> getwindowsversion()
sys.getwindowsversion(major=10, minor=0, build=19044, platform=2, service_pack='')
>>> getwindowsversion().build
19044
>>> getwindowsversion().platform_version
(10, 0, 19041)

It was changed here I guess:

It doesn’t mean anything except Windows versions are messy.

2 Likes

The version tuple (major, minor, build) that’s returned by sys.getwindowsversion() is subject to compatibility mode (e.g. Python is embedded in an application that has no manifest, which runs in Windows 8 compatibility mode). The value of the platform_version attribute is the file version of “kernel32.dll”, which is not affected by compatibility mode. However, this is based on old advice from Microsoft that’s no longer reliable in practice, at least not for the build number.

In 3.8-3.11, platform.platform() uses the version that’s reported by the CMD shell’s VER command. In 3.12, it queries the version using a new _wmi module (an undocumented, internal module; do not use the _wmi module directly).

3 Likes

@petersuter, @eryksun

Thank you so much for the detailed information, it’s very helpful.

2 Likes