如何使用 Apple Silicon 获得在 MacOS 上运行 Python 解释器的架构?
运行Python通用二进制文件(x86_64、arm64)时,如何从Python内部检查它是否正在运行x86_64或arm64可执行文件?似乎 os.uname() 和 platform.machine() 总是给出实际的系统架构(即“arm64”),而 sysconfig.get_platform( ) 总是会给出“universal2”(也没有帮助)。
那么如何区分 Python 作为 python3
或 arch -x86_64 python3
运行的区别呢?
When running a Python universal binary (x86_64, arm64), how can I check from within Python whether it is running the x86_64 or arm64 executable? It seems that os.uname()
and platform.machine()
would always give the actual system architecture (i.e. "arm64"), and sysconfig.get_platform()
would always give "universal2" (also not helping).
So how to tell the difference between Python being run as python3
or arch -x86_64 python3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我认为以下函数应该报告正确的机器体系结构(即正在运行的解释器的机器体系结构,而不是系统的体系结构),也适用于其他操作系统:
不幸的是,我无法访问 M1 Mac 进行双重检查。如果有人能确认这有效,那就太好了。
Okay, I think the following function should report the correct machine architectures (i.e. that of the running interpreter, not that of the system), also for other OS:
I unfortunately don't have access to a M1 Mac to double check. If someone could confirm that this works, that would be great.
我可以通过运行以下命令来获取它:
输出如下:
在 M1/M2 Mac 上 -->
arm
在较旧的 Mac 上 --> i386
I could get it by running this:
The output is as following:
On an M1/M2 Mac -->
arm
On an older Mac -->
i386