While it may work on some platforms, be aware that platform.architecture
is not always a reliable way to determine whether python is running in 32-bit or 64-bit. In particular, on OS X multi-architecture builds such as the Apple-supplied default with OS X 10.6, the same executable file may be capable of running in either mode, as the example below demonstrates. The safest multi-platform approach is to test sys.maxint
on Python 2.x or sys.maxsize
on Python 3.x.
$ /usr/bin/python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxint
(('64bit', ''), 9223372036854775807)
>>> ^D
$ export VERSIONER_PYTHON_PREFER_32_BIT=yes
$ /usr/bin/python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxint
(('64bit', ''), 2147483647)