2

In python2.7 it's simple, just import the lib platform. But how can i see if my windows is 32 or 64 bits? I work with a system build in python2.2 and can't find a way of do that :(

Any sugestions?

Irish Wolf
  • 211
  • 2
  • 13
  • 1
    possible duplicate of [How do I determine if my python shell is executing in 32bit or 64bit mode?](http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode) – Martijn Pieters Jul 31 '12 at 14:36
  • Just out of curiosity, why are you using Python 2.2? It's more than 10 years old and the new versions are as free as the old ones. – Fred Foo Jul 31 '12 at 14:38
  • @MartijnPieters: that checks whether the interpreter was built in 32-bits or 64-bits mode. It doesn't tell you much about the OS. – Fred Foo Jul 31 '12 at 14:39
  • :/ Because i work in a company that still use the python2.2 on our major application, i know it's sucks :/. @larsmans – Irish Wolf Jul 31 '12 at 14:41
  • @larsmans: you *may* have a 32-bit python interpreter on a 64-bit platform, but you cannot make that work the other way around. Thus, the two usually correlate. – Martijn Pieters Jul 31 '12 at 14:42
  • No access to Windows at this time, but have you looked at the [os module](http://docs.python.org/library/os.html) or [sys module](http://docs.python.org/library/sys.html)? Maybe [sys.platform](http://docs.python.org/library/sys.html#sys.platform) or [os.name](http://docs.python.org/library/os.html#os.name)? – GreenMatt Jul 31 '12 at 14:55
  • @sshekhar: Note the top of that document you linked to: *New in version 2.3.* – Martijn Pieters Jul 31 '12 at 15:00

2 Answers2

7

The platform module source code is informative.

Backported from there to determine the machine architecture on a Windows platform, it would use:

import os

def machine():
    try:
        return os.uname()[-1]
    except AttributeError:
        if "PROCESSOR_ARCHITEW6432" in os.environ:
            return os.environ.get("PROCESSOR_ARCHITEW6432", '')
        else:
            return os.environ.get('PROCESSOR_ARCHITECTURE', '')
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

In Python 2.x you can do this:

import sys
print sys.maxint  

And detect if it's 32/64 bit by sys.maxint.

Notice: this method may probably fail if you're running a 32 bit Python on a 64 bit machine.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
starrify
  • 14,307
  • 5
  • 33
  • 50