Ned Deily added the comment:
platform.architecture() is documented as giving unreliable results with macOS
universal files; see
https://docs.python.org/2/library/platform.html#platform.architecture. The
difference in behavior between Python 2.7 and 3.x for the example you show is
due to the difference in the value of sys.executable between them on macOS. On
2.7, sys.executable points to the actual Python interpreter binary, which is a
universal binary. On 3.x, the behavior was changed to not to resolve to the
interpreter binary but rather the stub launcher binary and the "-32" launcher
has only 32-bit executables:
$ /usr/local/bin/python2.7-32 -c 'import sys;print(sys.executable)'
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
$ /usr/local/bin/python3.6-32 -c 'import sys;print(sys.executable)'
/usr/local/bin/python3.6-32
Because platform.architecture() uses the "file" utility to examine the contents
of the file pointed to by sys.executable, this change in 3.x has the side
effect of producing the expected "32bit" value on 3.x when Python is invoked in
this manner.
However, that doesn't cover all cases. For example:
$ arch -i386 /usr/local/bin/python3.6 -c 'import
sys,platform;print(platform.architecture(), sys.maxsize > 2**32)'
('64bit', '') False
So the 3.x platform.architecture can still produce incorrect results. One can
argue about what value(s) platform.architecture() should return for
multi-architecture binaries; languishing Issue10735 covers that. One could
also argue that the value of sys.executable on 2.7 should be changed to behave
like 3.x but it's very late in the life of 2.7 to be making a change like that
and that change alone would not produce correct results for all cases, like
"arch -i386" above.
----------
assignee: -> lemburg
nosy: +lemburg
title: Python2.7-32 misreports architecture on macOS. ->
platform.architecture() with Python2.7-32 misreports architecture on macOS.
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29605>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com