is64bit.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. """is64bit.Python() --> boolean value of detected Python word size. is64bit.os() --> os build version"""
  2. import sys
  3. def Python():
  4. if sys.platform == 'cli': #IronPython
  5. import System
  6. return System.IntPtr.Size == 8
  7. else:
  8. try:
  9. return sys.maxsize > 2147483647
  10. except AttributeError:
  11. return sys.maxint > 2147483647
  12. def os():
  13. import platform
  14. pm = platform.machine()
  15. if pm != '..' and pm.endswith('64'): # recent Python (not Iron)
  16. return True
  17. else:
  18. import os
  19. if 'PROCESSOR_ARCHITEW6432' in os.environ:
  20. return True # 32 bit program running on 64 bit Windows
  21. try:
  22. return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') # 64 bit Windows 64 bit program
  23. except (IndexError, KeyError):
  24. pass # not Windows
  25. try:
  26. return '64' in platform.architecture()[0] # this often works in Linux
  27. except:
  28. return False # is an older version of Python, assume also an older os (best we can guess)
  29. if __name__ == "__main__":
  30. print("is64bit.Python() =", Python(), "is64bit.os() =", os())