[Pythonmac-SIG] machine architecture 32/64 with Python 2.6 on Snow Leopard?
Edward Moy
emoy at apple.com
Sat Sep 19 21:47:43 CEST 2009
I looked into the code for platform.architecture(), and it basically
runs the "file" command on /usr/bin/python. If the output contains
the string "64-bit", it will return "64bit" as the first tuple. So it
depends on what real question you are trying to answer, because in
SnowLeopard, /usr/bin/python is a wrapper program that does all the
versioning, reading preference files, etc, and is independent of the
real python executable: /System/Library/Frameworks/Python.framework/
Versions/2.6/Resources/Python.app/Contents/MacOS/Python.
Testing sys.maxint answers the question whether the current python in
running in 32 or 64-bit mode. platform.architecture() just tells if
the wrapper is "capable" of running 64-bit (it will run 64-bit by
default on 64-bit architectures, but could actually be running 32-bit,
either by choice or on 32-bit only hardware), and doesn't say anything
about the real python executable.
Ed
On Sep 18, 2009, at 5:46 PM, Bill Janssen wrote:
> I think I'm just going to put '32bit' or '64bit' in my installer
> name strings.
>
> Bill
>
> emoy at apple.com wrote:
>
>> On Sep 18, 2009, at 5:05 PM, Bill Janssen wrote:
>>
>>> William Kyngesburye <woklist at kyngchaos.com> wrote:
>>>
>>>> If you run the CLI 'uname -m' on any Intel Mac, it always has
>>>> returned
>>>> i386. So all it really means is 'Intel'.
>>>>
>>>> On Sep 18, 2009, at 5:53 PM, Bill Janssen wrote:
>>>>
>>>>> I'm running /usr/bin/python on SL, and
>>>>>
>>>>> import platform; print platform.machine()
>>>>>
>>>>> give me
>>>>>
>>>>> i386
>>>>>
>>>>> But Activity Monitor shows Python as "Intel (64-bit)".
>>>>>
>>>>> Is this a bug in platform.machine(), or am I misunderstanding what
>>>>> i386
>>>>> means? "platform.architecture()" returns ('64bit', '').
>>>
>>> Hmmm. So what's the pythonic way of getting i386 vs. x86_64?
>>>
>>> {'32bit': 'i386', '64bit': 'x86_64'}[platform.architecture()[0]]
>>>
>>> seems so complicated that there should be a routine for it in sys or
>>> platform.
>>
>> I don't know the "official" way, but what I do is:
>>
>> % python -c 'import sys;print sys.maxint'
>> 9223372036854775807
>> % env VERSIONER_PYTHON_PREFER_32_BIT=1 python -c 'import sys;print
>> sys.maxint'
>> 2147483647
>>
>> So I would look at sys.maxint to determine if python is running 32 or
>> 64-bit.
>>
>> Ed
More information about the Pythonmac-SIG
mailing list