Under Windows, I'm running a 32bits python.exe. I need to know if the OS/CPU is 64bits or 32bits.
My machine is running a Windows7 64bits.
Checked this post, and tried to run this Python script:
import ctypes; print(32 if ctypes.sizeof(ctypes.c_voidp)==4 else 64, 'bit CPU')
import sys; print("%x" % sys.maxsize, sys.maxsize > 2**32)
import struct; print( 8 * struct.calcsize("P"))
import platform; print( platform.architecture()[0] )
print( platform.machine() )
32 bit CPU
7fffffff False
32
32bit
AMD64
Most information you are querying is determined by the wordsize of the interpreter, not the CPU.
Only platform.machine()
ignores this information; it is taken from the system uname -m
data instead, which is the recommended command to determine if your system is 64-bit for both Linux and OS X, and Windows provides the exact same information (Python uses the C uname()
function in all cases).
Either test for 64
in that string, or build a set of acceptable values:
'64' in platform.machine()
or
platform.machine() in {'x86_64', 'AMD64'}