如何检测 Python 是否作为 64 位应用程序运行?
我正在对 Windows 注册表进行一些工作。根据 Python 运行为 32 位还是 64 位,某些键值会有所不同。如何检测 Python 是作为 64 位应用程序运行还是作为 32 位应用程序运行? (我对检测 32 位/64 位 Windows 不感兴趣 - 只是对 Python 平台感兴趣。)
I'm doing some work with the Windows registry. Depending on whether Python is running as 32-bit or 64-bit, certain key values will be different. How can I detect whether Python is running as a 64-bit application or as a 32-bit application? (I'm not interested in detecting 32-bit/64-bit Windows - just the Python platform.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Python 文档:
From the Python docs:
虽然它可能适用于某些平台,但请注意,
platform.architecture
并不总是确定 python 是在 32 位还是 64 位运行的可靠方法。特别是,在某些 OS X 多架构构建上,相同的可执行文件可能能够在任一模式下运行,如下面的示例所示。最快的安全多平台方法是在 Python 2.6、2.7、Python 3.x 上测试sys.maxsize
。While it may work on some platforms, be aware that
platform.architecture
is not always a reliable way to determine whether python is running in 32-bit or 64-bit. In particular, on some OS X multi-architecture builds, the same executable file may be capable of running in either mode, as the example below demonstrates. The quickest safe multi-platform approach is to testsys.maxsize
on Python 2.6, 2.7, Python 3.x.