我在为我的macports python2.7触发32位python时遇到了一些麻烦。
calvins-MacBook ttys003 Tue Nov 01 01:04:23 |~|
calvin$ arch -arch x86_64 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>> exit()
calvins-MacBook ttys003 Tue Nov 01 01:04:49 |~|
calvin$ arch -arch i386 python
Python 2.7.2 (default, Oct 31 2011, 20:10:35)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.10.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform; platform.architecture()
('64bit', '')
>>>
我应该如何触发使用32位python?
答案 0 :(得分:3)
arch -i386 python
将以32位模式运行二进制文件(这就是你所做的)。
如果您通过MacPorts安装了Python,请检查它是否实际上是使用32位和64位(通用二进制文件)构建的。
file `which python`
这是我的输出:
λ > file /usr/local/bin/python
/usr/local/bin/python: Mach-O universal binary with 2 architectures
/usr/local/bin/python (for architecture i386): Mach-O executable i386
/usr/local/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
如果您没有看到i386
,那么您的版本没有32位版本。
虽然如果你可以运行arch -i386 python
,你应该没问题,因为如果你的二进制文件无法运行32位模式,你会收到错误。
另外,不要依赖platform.architecture()
告诉你它是否是32位,因为即使你是32位,通用二进制文件也会报告64位模式。最好依赖sys.maxsize
,这取决于你是在32位还是64位模式。
Python采用32位模式,请注意sys.maxsize > 2**32
:
λ > arch -i386 python
Python 2.7.2 (default, Oct 31 2011, 00:51:07)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxsize > 2**32
False
>>> sys.maxsize
2147483647
>>> import platform
>>> platform.architecture()
('64bit', '')
64位模式下的Python:
λ > python
Python 2.7.2 (default, Oct 31 2011, 00:51:07)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxsize
9223372036854775807
>>> sys.maxsize > 2**32
True
>>> import platform
>>> platform.architecture()
('64bit', '')