By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Thanks, Ken
Jul 15 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
kj*******@gmail.com wrote:
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?

Thanks, Ken
How about sys.maxint? 64 bit returns 9223372036854775807 on 64-bit
Linux for me.

-Larry
Jul 15 '08 #2

P: n/a
On Jul 16, 6:10 am, kjhish...@gmail.com wrote:
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'
>>x = sys.maxint
n = 1
while x:
.... n += 1
.... x >>= 1
....
>>n
32

WARNING: Assumes nobody will be silly enough to build a machine with
ones-complement integers in future :-)
Jul 16 '08 #3

P: n/a
kj*******@gmail.com wrote:
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?

Thanks, Ken
On my windows box this works:
>>platform.architecture()
('32bit', 'WindowsPE')
David
Jul 16 '08 #4

P: n/a
David Lees wrote:
kj*******@gmail.com wrote:
>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?

Thanks, Ken

On my windows box this works:
>>platform.architecture()
('32bit', 'WindowsPE')
David
On Fedora Core 5 64-bit here is what I see:
>>import platform
platform.architecture()
('64bit', 'ELF')

-Larry
Jul 16 '08 #5

P: n/a
>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
Jul 16 '08 #6

P: n/a
Ken Hartling wrote:
Thanks .. but I want to find out if the system is "running on 64bit"
even when the interpreter is a 32-bit build executable ("what python
was built on"). platform.architecture() and platform() in general
seems to only be looking at the build executable
You can pass in an arbitrary binary to architecture(), so I guess you
could use this on some suitable thing under "/bin" on a Unix box. This
doesn't work on Windows, though.

In this message,

http://mail.python.org/pipermail/pyt...ne/326158.html

Thomas Heller suggests using ctypes to call the Windows API directly; so
something like this could work:
>>import ctypes, sys
i = ctypes.c_int()
kernel32 = ctypes.windll.kernel32
process = kernel32.GetCurrentProcess()
kernel32.IsWow64Process(process, ctypes.byref(i))
1
>>is64bit = (i.value != 0)
is64bit
False

(IsWow64Process returns a non-zero value if it manages to check the
status, and sets the variable to a non-zero value if the process is
running under WOW64. I only have 32-bit boxes here, so it's only
partially tested).

And yes, looks like official support for this might appear in 2.6:

http://mail.python.org/pipermail/pyt...ay/079022.html

(in that thread, Mark Hammond suggests "'64 bit' in sys.version" as a
workaround, but warns for false negatives).

</F>

Jul 16 '08 #7

P: n/a
Fredrik Lundh wrote:
Ken Hartling wrote:
Thanks .. but I want to find out if the system is "running on 64bit"
even when the interpreter is a 32-bit build executable ("what python
was built on"). platform.architecture() and platform() in general
seems to only be looking at the build executable

You can pass in an arbitrary binary to architecture(), so I guess you
could use this on some suitable thing under "/bin" on a Unix box. This
doesn't work on Windows, though.

In this message,

http://mail.python.org/pipermail/pyt...ne/326158.html

Thomas Heller suggests using ctypes to call the Windows API directly; so
something like this could work:
>>import ctypes, sys
>>i = ctypes.c_int()
>>kernel32 = ctypes.windll.kernel32
>>process = kernel32.GetCurrentProcess()
>>kernel32.IsWow64Process(process, ctypes.byref(i))
1
>>is64bit = (i.value != 0)
>>is64bit
False
This is included in the latest pywin32-211 as well:

<code>
import win32process
print win32process.IsWow64Process ()

</code>

TJG
Jul 16 '08 #8

P: n/a
Tim Golden wrote:
This is included in the latest pywin32-211 as well:

<code>
import win32process
print win32process.IsWow64Process ()
</code>
on the other hand, "ctypes" is only an import away if you have a current
Python...

</F>

Jul 16 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.