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

K

kjhishere

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
 
J

John Machin

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?
.... n += 1
.... x >>= 1
....32

WARNING: Assumes nobody will be silly enough to build a machine with
ones-complement integers in future :)
 
D

David Lees

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
('32bit', 'WindowsPE')


David
 
M

Martin v. Löwis

I need to know if I'm running on 32bit or 64bit ... so far I haven't
'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
 
F

Fredrik Lundh

Ken said:
> 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/python-list/2005-June/326158.html

Thomas Heller suggests using ctypes to call the Windows API directly; so
something like this could work:
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/python-dev/2008-May/079022.html

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

</F>
 
T

Tim Golden

Fredrik said:
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/python-list/2005-June/326158.html

Thomas Heller suggests using ctypes to call the Windows API directly; so
something like this could work:

False

This is included in the latest pywin32-211 as well:

<code>
import win32process
print win32process.IsWow64Process ()

</code>

TJG
 
F

Fredrik Lundh

Tim said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top