首页 > 解决方案 > 如何通过 python 代码检测我的操作系统是 32 位还是 64 位

问题描述

我想通过python代码知道系统类型(os)。我尝试过返回 32 位的 platform.architecture(),Windows PE 因为我的操作系统是 64 位。

如果系统类型(操作系统)是 32 位,它将返回什么?

提前致谢!

标签: python-3.x

解决方案


import platform
platform.architecture()
  ('32bit', 'WindowsPE')

在 64 位 Windows 上,32 位 Python 返回:

 ('32bit', 'WindowsPE') # Don't know why.

一个好方法是写一个函数

def check_os_type():
    if platform.machine().endswith('64'):
        return '64 bit'
    if  platform.machine().endswith('32'):
        return '32 bit'

推荐阅读