tags:

views:

54

answers:

2

I got the following error when compiling sip with --arch x86_64 option.

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

I found that the prebuilt Mac OS X python (snow leopard) is universal, and it doesn't get the 64 bit library. I guess it's running on 32bit mode.

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

How can I force python to run on 64bit mode? When I run the same code on Textmate, there's no problem. So, I think Textmate should run on 64 bit mode anyway.

Added

  • This link shows how to identify if a python that I'm running is 32bit or 64bit. And I checked my python is 32 bit.
  • This link shows how to make 32/64bit python. But it doesn't work for me.
+2  A: 

Try using arch(1), and supply the specific version of Python:

arch -x86_64 /usr/bin/python2.6

Actually the system should choose the first suitable architecture for you. As

$ 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

If that python somehow chooses 2.5, then you can't use 64-bit, but if it chooses 2.6 then the x86_64 variant should be automatically selected, as commented below. If it's the former, try to get python_select and change the version to 2.6.

KennyTM
Shouldn't need to do this in 10.6, as python 2.6 and 3.0 default to 64-bit and 2.5 is only available in 32-bit. Which version of Mac OS X are you using @prosseek?
jshier
I use 10.6.4, and arch -x86_64 doesn't work for me. I added more comments.
prosseek
@pro: See update.
KennyTM
It works. Thanks!
prosseek
@Kenny: It's weird, but it uses i386 not x86_64 as default.
prosseek
While that does currently work with the Apple-supplied python2.6 in 10.6 and - as noted above - only if you use the specific versioned path in `/usr/bin`, be aware that the Apple-documented way of controlling this is different and could change in the future. The documented way involves using the `python` command and either setting the `VERSIONER_PYTHON_PREFER_32_BIT` env variable or changing a default plist. See `man 1 python` for more info. Also, for other pythons, like the MacPorts or python.org installer pythons, the simple `arch` method won't work for pythons prior to 2.7 (or 3.2).
Ned Deily
+1  A: 

Okay, be REALLY careful when you do this, it's going to require other things to also be 64-bit. All of a sudden, if mod_python won't work, then you need to recompile apache. Then all your python modules like tkinter/tix. If you're on 10.5 like me, don't go there, just live with 32-bit for it.

And if you don't know about http://www.macports.org/ then remember that it's your friend. :-)

eruciform