How to figure out if the platform is 32bit or 64bit?

"Martin v. Löwis" martin at v.loewis.de
Wed Jul 16 01:43:40 EDT 2008


>> I need to know if I'm running on 32bit or 64bit ... so far I haven't
>> come up with how to get this info via python. sys.platform returns
>> what python was built on ... but not what the current system is.
>>
>> I thought platform.uname() or just platform.processor() would have
>> done it, but python returns an empty string on windows. Any ideas?
>>
> 
>>>> import sys
>>>> hex(sys.maxint)
> '0x7fffffff'

I don't think that will satisfy the OP. Apparently, he wants to find
out that the system is "running on 64bit" even when the interpreter is a
32-bit build executable ("what python was built on").

I don't think Python supports querying that information in general
(i.e. "is the microprocessor supporting a 64-bit address space, even
if the current process, and perhaps the current operating system
only uses a 32-bit address space?")

It is possible to answer that question with Python in a
platform-specific manner, but the answer is more difficult than a
single yes/no:
- is the processor capable of executing 64-bit code?
- is the operating system kernel operating the processor in 64-bit
  mode?
- does the operating system support 64-bit user-space applications?
  (in some OSX and Solaris releases, the answer to this question
   was no, even though the answer to the previous question was yes,
   IIRC)
- does the Python binary support 64-bit mode?
- is the Python binary running in 64-bit mode?
  (again, this may vary from the previous question, in case of
   fat (universal) binaries)

Whether any of these questions are of interest, and which of them
the OP wanted to ask, I don't know.

Regards,
Martin



More information about the Python-list mailing list