2011-10-31 45 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