How do I determine if my python shell is executing in 32bit or 64bit?

前端 未结 18 1143
北恋
北恋 2020-11-22 04:25

I need a way to tell what mode the shell is in from within the shell.

While I\'m primarily an OS X user, I\'d be interested in knowing about other platforms as well.<

相关标签:
18条回答
  • 2020-11-22 04:39

    platform.architecture() notes say:

    Note: On Mac OS X (and perhaps other platforms), executable files may be universal files containing multiple architectures.

    To get at the “64-bitness” of the current interpreter, it is more reliable to query the sys.maxsize attribute:

    import sys
    is_64bits = sys.maxsize > 2**32
    
    0 讨论(0)
  • 2020-11-22 04:41

    struct.calcsize("P") returns size of the bytes required to store a single pointer. On a 32-bit system, it would return 4 bytes. On a 64-bit system, it would return 8 bytes.

    So the following would return 32 if you're running 32-bit python and 64 if you're running 64-bit python:

    Python 2

    import struct;print struct.calcsize("P") * 8
    

    Python 3

    import struct;print(struct.calcsize("P") * 8)
    
    0 讨论(0)
  • 2020-11-22 04:43

    Basically a variant on Matthew Marshall's answer (with struct from the std.library):

    import struct
    print struct.calcsize("P") * 8
    
    0 讨论(0)
  • 2020-11-22 04:44

    For a non-programmatic solution, look in the Activity Monitor. It lists the architecture of 64-bit processes as “Intel (64-bit)”.

    0 讨论(0)
  • 2020-11-22 04:45

    Open python console:

    import platform
    platform.architecture()[0]
    

    it should display the '64bit' or '32bit' according to your platform.

    Alternatively( in case of OS X binaries ):

    import sys
    sys.maxsize > 2**32 
    # it should display True in case of 64bit and False in case of 32bit
    
    0 讨论(0)
  • 2020-11-22 04:45

    Do a python -VV in the command line. It should return the version.

    0 讨论(0)
提交回复
热议问题