如何以可在Linux,Windows和MacOS上移植的方式收集Python 3中的当前体系结构?

问题描述

我正在尝试找到一种可移植的方式来收集当前体系结构(例如x86_64AArch64),该体系结构将用于使用Python 3填充is_x86之类的标志

看起来import platform; platform.machine()函数是正确的函数,但是它给了我不同的字符串,最终代表了相同的(广泛地说)基础架构:

在Linux x86_64上:

Python 3.6.9 (default,Nov  7 2019,10:44:02) 
[GCC 8.3.0] on linux
Type "help","copyright","credits" or "license" for more information.
>>> import platform; platform.machine()
'x86_64'

Windows x86_64:

Python 3.6.8 (tags/v3.6.8:3c6b436a57,Dec 24 2018,00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
>>> import platform; platform.machine()
'AMD64'

MacOS x86_64:

Python 3.7.7 (default,Mar 10 2020,15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help","credits" or "license" for more information.
>>> import platform; platform.machine()
'x86_64'

在x86(32位)系统上也报告了i386

还有其他方法可以通过便携式方式可靠地收集体系结构吗?

解决方法

我发现更简单的方法是:

import platform

is_x86 = platform.machine() in ("i386","AMD64","x86_64")

由于在不同操作系统下返回的字符串不同,因此这是必需的。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...