如何在Mac OS X上强制使用64位python?

使用–arch x86_64选项编译sip时出现以下错误.

prosseek:siplib smcho$python -c 'import sip; print sip'
Traceback (most recent call last):
  File "", line 1, in 
ImportError: dlopen(./sip.so, 2): no suitable image found.  Did find:
        ./sip.so: mach-o, but wrong architecture

我发现预构建的Mac OS X python(雪豹)是通用的,它没有得到64位库.我猜它在32位模式下运行.

file /usr/bin/python 
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64):      Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):        Mach-O executable i386
/usr/bin/python (for architecture ppc7400):     Mach-O executable ppc
prosseek:siplib smcho$file sip.so
sip.so: Mach-O 64-bit bundle x86_64

如何强制python在64位模式下运行?当我在Textmate上运行相同的代码时,没有问题.所以,我认为Textmate无论如何都应该在64位模式下运行.

添加

> This link显示了如何识别我正在运行的python是32位还是64位.我检查了我的python是32位.
> This link显示了如何制作32 / 64bit python.但它对我不起作用.

最佳答案
尝试使用arch(1),并提供特定版本的Python:

arch -x86_64 /usr/bin/python2.6

实际上系统应该为您选择第一个合适的架构.如

$file /usr/bin/python2.5
/usr/bin/python2.5: Mach-O universal binary with 2 architectures
/usr/bin/python2.5 (for architecture i386): Mach-O executable i386
/usr/bin/python2.5 (for architecture ppc7400):  Mach-O executable ppc

$file /usr/bin/python2.6
/usr/bin/python2.6: Mach-O universal binary with 3 architectures
/usr/bin/python2.6 (for architecture x86_64):   Mach-O 64-bit executable x86_64
/usr/bin/python2.6 (for architecture i386): Mach-O executable i386
/usr/bin/python2.6 (for architecture ppc7400):  Mach-O executable ppc

如果那个python以某种方式选择2.5,那么你不能使用64位,但是如果它选择2.6那么应该自动选择x86_64变体,如下面的评论.如果是前者,请尝试获取python_select并将版本更改为2.6.

转载注明原文:如何在Mac OS X上强制使用64位python? - 代码日志