首页 > 解决方案 > 什么 platform.system() 和 platform.architecture() 在 Apple M1 Silicon 上返回?

问题描述

我没有可以使用的 M1 Mac,我读到 python 支持它。这些功能在 m1 Mac 上的回报是什么?

platform.system()
platform.architecture()

谢谢。

标签: python-3.xarchitecturesystemapple-silicon

解决方案


在实际的 M1 Mac 上,该platform模块返回以下值:

shuuji3@momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:03)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-arm64-arm-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'arm'

除此之外,在 Rosetta 2(Intel 模式)下,platform模块返回以下内容:

(注意:对于第一个命令,我按照文章如何在 Apple Silicon | Walled Garden Farmers 上运行旧版命令行应用程序中的说明进行操作。)

shuuji3@momo ~ % env /usr/bin/arch -x86_64 /bin/zsh --login
shuuji3@momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:04)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-x86_64-i386-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'i386'

我们可以用来区分当前 M1 mac 使用的是哪种模式。


推荐阅读