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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kjhishere@gmail.com

    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
  • Larry Bates

    #2
    Re: How to figure out if the platform is 32bit or 64bit?

    kjhishere@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

    Comment

    • John Machin

      #3
      Re: How to figure out if the platform is 32bit or 64bit?

      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 :-)

      Comment

      • David Lees

        #4
        Re: How to figure out if the platform is 32bit or 64bit?

        kjhishere@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

        Comment

        • Larry Bates

          #5
          Re: How to figure out if the platform is 32bit or 64bit?

          David Lees wrote:
          kjhishere@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

          Comment

          • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

            #6
            Re: 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?
            >>
            >
            >>>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

            Comment

            • Fredrik Lundh

              #7
              Re: How to figure out if the platform is 32bit or 64bit?

              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,



              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:



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

              </F>

              Comment

              • Tim Golden

                #8
                Re: How to figure out if the platform is 32bit or 64bit?

                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,
                >

                >
                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

                Comment

                • Fredrik Lundh

                  #9
                  Re: How to figure out if the platform is 32bit or 64bit?

                  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>

                  Comment

                  Working...