473,611 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?

Thanks, Ken
Jul 15 '08 #1
8 5940
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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?

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

-Larry
Jul 15 '08 #2
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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?
>>import sys
hex(sys.maxin t)
'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
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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?

Thanks, Ken
On my windows box this works:
>>platform.arch itecture()
('32bit', 'WindowsPE')
David
Jul 16 '08 #4
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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?

Thanks, Ken

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

-Larry
Jul 16 '08 #5
>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.proces sor() would have
done it, but python returns an empty string on windows. Any ideas?
>>>import sys
hex(sys.maxi nt)
'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
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.archit ecture() 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.k ernel32
process = kernel32.GetCur rentProcess()
kernel32.IsWo w64Process(proc ess, 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
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.archit ecture() 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.k ernel32
>>process = kernel32.GetCur rentProcess()
>>kernel32.IsWo w64Process(proc ess, 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.Is Wow64Process ()

</code>

TJG
Jul 16 '08 #8
Tim Golden wrote:
This is included in the latest pywin32-211 as well:

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

</F>

Jul 16 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3037
by: Peter Hartmann | last post by:
Hello, I could really use some help. I'm trying to install a python program on centos4 x86_64. When I run 'python setup.py' it ends up in /usr/lib64/python2.3/site-packages/ instead of /usr/lib/python2.3/site-packages. It's a problem because the program I'm trying to install is a dependency for something that is only 32bit. How can I specify a 32bit install? What I've tried so far: When I try 'python setup.py build --build-lib...
0
2915
by: GDB500 | last post by:
Can you help with code to convert from 64bit to 32bit other than just A=B :confused: The full story is that I have a 64bit float in hexidecimal so first I need to get this into a 64bit float Then using ANDs and Divides extract the Exponent and Mantissa and then get it into a 32bit float Thanks
28
2721
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am developing C++ COM native code (unmanaged C++) using Visual Studio 2005. I do not take any new features of 64-bit platform, and currently my code runs fine on 32-bit platform (e.g. Windows XP SP2). Now I am researching how to build my code for 64-bit platform (e.g. Windows 2003 Server 64-bit R2)? Any options I need to specify in Visual Studio 2005? The best solution to me is to make a single build for both 32-bit...
2
2161
by: M O J O | last post by:
(I'm using Visual Studio 2008) I want my new develloper pc to be Vista 64bit, but all my clients are so far 32bit (XP), so my questions are: 1) Is it possible for me to tell VS2008 that the output should be 32bit? That is devellop dotnet on a 64bit machine and output 32bit program? 2) When later this year, all my clients are updgraded to Vista 64bit, can I then tell VS2008 easialy to change my solution from 32bit to 64bit?
0
2980
by: Leo Park | last post by:
Hello, guys. I want to compile 32bit *.c and *.cc files On 64bit x86_64 systems. But, it is not work. --------------------------------------------------------------------------------------------------------------- bmk_mgr@ikdp101: gcc --version gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
1
3469
by: Morfys | last post by:
Hi, I would like to copy glibc/libgcc (in particular, libc.so. 6,libgcc_s.so.1) for a 32bit machine onto a 64bit machine. Would using the 32bit glibc/libgcc on the 64bit machine work? The reason I ask is that I've been getting the following error: Bin/libc.so.6: symbol _dl_out_of_memory, version GLIBC_PRIVATE not defined in file ld-linux.so.2 with link time reference
1
1877
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi all, I built an app with the "Platform target" of x86. Then I installed it as a Windows Service. When it's running, I can see in the Task Manager that the executable has "*32" following it, which I think means it's running in 32bit. But after I changed the log on account of the service, the "*32" disappeared and it's running in 64bit. Is there any way to fix this? I need to run it in 32bit. Thanks.
0
1338
by: Paul McNett | last post by:
Gary Josack wrote: I just tried it: WindowsXP in Parallels Desktop: ('32bit', 'WindowsPE') Ubuntu 7.10 in Parallels Desktop: ('32bit', '')
3
5240
by: sudhivns | last post by:
Hi , Does Volume Shadow Copy Service 7.2 SDK work with XP 64bit platform. We have seen issues with compiling(using vssapi.lib ) the c++ application. Same SDK work for XP 32bit and XP 64bit ? Are there any architecture(Intel,AMD) specific libraries on XP. Regards, Sudhi
0
8149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8097
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8596
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4108
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.