如何确定我的python shell是在32位还是64位执行? [英] How do I determine if my python shell is executing in 32bit or 64bit?
问题描述
我需要一种方法,可以从外壳内部分辨出外壳所处的模式.
I need a way to tell what mode the shell is in from within the shell.
虽然我主要是OS X用户,但我也想了解其他平台.
While I'm primarily an OS X user, I'd be interested in knowing about other platforms as well.
我尝试查看平台模块,但这似乎只是在告诉您关于关于可执行文件所使用的位架构和链接格式"的内容:尽管该二进制文件被编译为64位(我在OS X 10.6上运行),所以即使我正在使用此处所述强制32位模式).
I've tried looking at the platform module but it seems only to tell you about "about the bit architecture and the linkage format used for the executable": the binary is compiled as 64bit though (I'm running on OS X 10.6) so it seems to always report 64bit even though I'm using the methods described here to force 32bit mode).
推荐答案
一种方法是按照
顺便说一句,您可能很想为此使用 BTW, you might be tempted to use 这篇关于如何确定我的python shell是在32位还是64位执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! sys.maxsize
是Python 2.6中引入的.如果您需要针对较旧系统的测试,则此稍微复杂一些的测试应适用于所有Python 2和3版本:sys.maxsize
was introduced in Python 2.6. If you need a test for older systems, this slightly more complicated test should work on all Python 2 and 3 releases:$ python-32 -c 'import struct;print( 8 * struct.calcsize("P"))'
32
$ python-64 -c 'import struct;print( 8 * struct.calcsize("P"))'
64
platform.architecture()
.不幸的是,它的结果并不总是可靠的,尤其是在OS X通用二进制文件中.platform.architecture()
for this. Unfortunately, its results are not always reliable, particularly in the case of OS X universal binaries.$ arch -x86_64 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit True
$ arch -i386 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit False