Search code examples
python32bit-64bit

How do I detect if Python is running as a 64-bit application?


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.)


Solution

  • import platform
    platform.architecture()
    

    From the Python docs:

    Queries the given executable (defaults to the Python interpreter binary) for various architecture information.

    Returns a tuple (bits, linkage) which contain information about the bit architecture and the linkage format used for the executable. Both values are returned as strings.