I\'m trying to build a Python extension on MacOSX 10.6 and to link it against several frameworks (i386 only). I made a setup.py file, using distutils and the Extension object.>
I am not sure I understand what you are trying to do and your desired outcome but perhaps this will help. Because C extension modules are normally run within the execution context of the Python interpreter, extension modules have to be built to be compatible with the interpreter. On OS X, Python and distutils go to some trouble to ensure that C extension modules are built with the same SDK (-sysroot
), MACOSX_DEPLOYMENT_TARGET
value, and -arch
values as the Python interpreter itself was originally built. So, if you are using the Apple-supplied Python on 10.6, distutils will supply -arch i386 -arch ppc -arch x86_64
, the three archs that it was built with. If you use a current python.org OS X installer (on 10.6, 10.5, or 10.4), it will use:
gcc-4.0 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
From the snippets you supply, I'm guessing you are using a MacPorts-installed universal Python and, by default, it is built with and uses -arch x86_64 -arch i386 -isysroot /
for building extension modules.
Generally, to make everything work you need to ensure:
there is at least one arch
in
common among the interpreter, all C
extension modules, and all external
frameworks and/or shared libraries
that they link to
the interpreter is executing in that (or one of those) common architecture(s).
On OS X 10.6, that last step is not as easy as it should be depending on which Python you are using. For instance, the Apple-supplied Python 2.6 has a modification to force 32-bit execution (see Apple's man python
for details):
export VERSIONER_PYTHON_PREFER_32_BIT=yes
If you build your own 32-/64-bit universal Python, there are fixes in 2.6.5 to allow selection at run-time. Unfortunately, the way MacPorts builds Python bypasses those fixes so there does not appear to be any simple way to force a MacPorts python2.6 32-/64-bit universal build on 10.6 to run in 32-bit mode. For complicated reasons, it will always prefer 64-bit, if available, even if you use /usr/bin/arch -i386
.
So, depending on what you are trying to do, you may be able to work around the issue (if I understand it correctly) by either:
-arch x86_64
/usr/bin/python
) in 32-bit mode or the python.org 2.6.5reinstall the MacPorts python in 32-bit-only mode (untested!):
sudo port selfupdate
sudo port clean python26
sudo port install python26 +universal universal_archs=i386