2011-10-31 61 views
0

的我有一些麻烦触发了我的MacPorts 32位蟒蛇python2.7强制使用32位的蟒蛇

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位蟒蛇的?

回答

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位模式。在64位模式下

λ > 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', '') 

的Python::

的Python在32位模式下,注意sys.maxsize > 2**32

λ > 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', '') 
+0

笔记,'拱-i386'不会对10.6 10.7对未修饰的工作2.7和3.2之前的32位/ 64位通用蟒蛇。另外,10.6和10.7版本的Apple提供的Pythons系统支持另一种通过环境变量或plist默认值选择32位和64位的方法。有关详细信息,请参阅Apple的python“man”页面。 –

+0

的信息@Ned感谢,我一直在处理这种如果在过去几天的情况。 – birryree