Inconsistent results from platform.machine() on Windows ARM64
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
Running x86 and AMD64 builds of Python 3.11.0 (official binary releases) in emulation on Windows 11 on an ARM64 machine gives me
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.machine()
'AMD64'
Python 3.11.0 (main, Oct 24 2022, 18:13:38) [MSC v.1933 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.machine()
'ARM64'
This seem inconsistent. I would expect both to return 'ARM64', the actual underlying processor architecture, in the same way as running an x86 build on AMD64 returns 'AMD64'. But even if they were reporting the emulated architecture, it should be 'AMD64' and 'x86', not 'AMD64' and 'ARM64' (or possibly 'AMD64' and 'AMD64', if x86 binaries are also handled by the AMD64 emulator, I have no idea how that works).
This makes it hard to distinguish between an AMD64 build running on ARM64 and an AMD64 build running on AMD64. In fact, the only platform function that gives any indication at all is processor(), and parsing the desired information out of the free-form text returned by that seems fiddly. ('ARMv8 (64-bit) Family 8 Model 0 Revision 0, ' and 'Intel64 Family 6 Model 44 Stepping 2, GenuineIntel' here.)
Relatedly, how do I distinguish between an ARM64 build running on ARM64 and an AMD64 build running on ARM64? The inconsistency above makes them differ in platform.machine(), but what if that were fixed? This seems like a job for platform.architecture(), which is explicitly meant to give information about the running binary, but that just returns ('64bit', 'WindowsPE') in both cases. platform.python_compiler() happens to have that information ('MSC v.1933 64 bit (ARM64)' vs. 'MSC v.1933 64 bit (AMD64)'), but again that is fiddly free-form text and may not work for other compilers than MSC.
Your environment
- CPython versions tested on: 3.11.0
- Operating system and architecture: Windows 11 10.0.22000 ARM64, Windows 10 10.0.19043 AMD64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Windows ARM64 behavior and compare platform.machine(), platform.architecture(), platform.processor(), and platform.python_compiler() for native and emulated builds. Read the platform module documentation and implementation to determine the intended distinction between host and running-binary architecture. Done means the behavior and API semantics are consistent and documented, with coverage for the reported combinations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100