views:

667

answers:

1

I have a third-party library (the interface to Xerox's Finite State tools) which come as universal binaries with two variants internally: a PPC and an i386 variant. I also have a Python interface to the library (which uses ctypes).

But when I try to run the example code provided with the Python interface I get an error complaining about the library being the wrong architecture:

ImportError: dlopen(/Users/arne/sw/lib/libxcfsm.dylib, 10): no suitable image found. Did find:
/Users/arne/sw/lib/libxcfsm.dylib: mach-o, but wrong architecture

From what I can gather, this is because the python executables have an x86_64 variant internally in addition to the two versions in my library, and prefer to run in that mode. Is there some way for me to force the python executable to start the i386 version rather than the x86_64 one, for just some scripts?

+9  A: 

If you are using the apple system python (on snow leopard) you can execute it with

arch -i386 python

eg:

robin-mbp:~ $ arch -i386 /usr/bin/python2.6 -c "import sys; print sys.maxint"
2147483647

to start the interpreter in 32 bit mode. There is also an environment variable you can set for the system python (VERSIONER_PYTHON_PREFER_32_BIT).

If it is your own built python there is currently a bug with arch selection, but if you rebuild with the pythonw.c from this ticket it works fine.

thrope
That did it. Thanks a lot!
arnsholt