I'm running python 2.6 on Linux, Mac OS, and Windows, and need to determine whether the kernel is running in 32-bit or 64-bit mode. Is there an easy way to do this?
I've looked at platform.machine(), but this doesn't work properly on Windows.
I've also looked at platform.architecture(), and this doesn't work when running 32-bit python on 64-bit Windows.
Note: It looks like python 2.7 has a fix that makes platform.architecture() work correctly. Unfortunately, I need to use python 2.6 (at least for now).
(edit: From talking to folks off-line, it sounds like there probably isn't a robust python-only way to make this determination without resorting to evil hacks. I'm just curious what evil hacks folks have used in their projects that use python 2.6. For example, on Windows it may be necessary to look at the PROCESSOR_ARCHITEW6432 environment variable and check for AMD64)
Python Version Bit – Does My Python Shell Run 32 Bit or 64 Bit Version? To check which bit version the Python installation on your operating system supports, simply run the command “ python ” (without quotes) in your command line or PowerShell (Windows), terminal (Ubuntu, macOS), or shell (Linux).
Most modern operating systems use a 64-bit edition of Python by default. Windows users can run 32-bit editions of Python on 64-bit Windows, but at a slight cost of performance. 32-bit Python, and 32-bit apps generally, can access only 4GB of memory at a time.
Method 1: Use uname -a to check 32-bit or 64-bit. Linux provides a command called uname, which prints system information including kernel version and whether kernel is 32 bit or 64 bit. If the uname -a output displays x86_64, then the system is running 64bit Linux kernel.
>>> import platform
>>> platform.architecture()
('32bit', 'ELF')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With