Inconsistent results from platform.machine() on Windows ARM64
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 Windows ARM64 的行为,并比较原生构建和模拟构建中的 platform.machine()、platform.architecture()、platform.processor() 与 platform.python_compiler()。阅读 platform 模块的文档和实现,以确定 host 架构与正在运行的二进制文件架构之间预期的区别。完成的标准是行为和 API 语义保持一致并有文档说明,同时覆盖报告中的组合。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100