Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, how do you determine whether the kernel is running in 32-bit or 64-bit mode?

Tags:

python

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)

like image 325
Matt Ball Avatar asked Aug 23 '11 17:08

Matt Ball


People also ask

How do you check if you are running 32 or 64-bit Python?

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

Is Python 32-bit or 64-bit?

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.

Is my kernel 32 or 64-bit?

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.


1 Answers

>>> import platform
>>> platform.architecture()
('32bit', 'ELF')
like image 170
Gabi Purcaru Avatar answered Oct 27 '22 11:10

Gabi Purcaru