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

问题描述 投票:0回答:3

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

platform.system()
platform.architecture()

谢谢。

python-3.x architecture system apple-silicon
3个回答
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'

除此之外,在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'

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

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


0
投票

我有一台 M1 pro,输出是:

Python 3.8.15 (default, Nov 10 2022, 13:17:42) 
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import platform
>>> platform.platform()
'macOS-10.16-x86_64-i386-64bit'
>>> platform.system()
'Darwin'

0
投票

为了了解更多背景信息,这里有一些关于英特尔与苹果的更多价值:

% arch -x86_64 python3
Python 3.11.4 (v3.11.4:d2340ef257, Jun  6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
>>> platform.machine()
'x86_64'
>>> platform.processor()
'i386'

% python3
Python 3.11.4 (v3.11.4:d2340ef257, Jun  6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
>>> platform.machine()
'arm64'
>>> platform.processor()
'arm'

© www.soinside.com 2019 - 2024. All rights reserved.