Check if Python interpreter is 32 or 64 bit
32-bit Python binaries can run on 64-bit OS. To precisely detect if the operating system is 64-bit or 32-bit, check if Python itself is 32-bit to avoid falsely detecting a 64-bit OS as 32 bit. This check is just for the Python interpreter. To detect OS parameters in a cross-platform-robust way further checks are necessary.
python -c "import sys; print(sys.maxsize > 2**32)"
- 32-bit Python will print
False
- 64-bit Python will print
True
In a script:
import sys
def is_64bit() -> bool:
return sys.maxsize > 2**32