Apple M1 Silicon 上的 platform.system() 和 platform.architecture() 返回什么?

jos*_*ntt 7 architecture system python-3.x apple-silicon

我没有 M1 Mac 可以使用,我读到 python 支持它。这些函数在 m1 Mac 上的返回结果是什么?

platform.system()
platform.architecture()
Run Code Online (Sandbox Code Playgroud)

谢谢。

shu*_*ji3 6

在实际的 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'
Run Code Online (Sandbox Code Playgroud)

除此之外,在Rosetta 2(Intel模式)下,platform模块返回不同的值,如下所示:

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'
Run Code Online (Sandbox Code Playgroud)

注意:对于第一个命令,我按照如何在 Apple Silicon 上运行旧版命令行应用程序一文中的说明进行操作。围墙花园农民

我们可以使用这些值来区分当前M1 mac在哪种模式下运行应用程序。