Using the Autodesk FBX Python module on 64-bit Macs

,

This is a copy of a bug report I sent to Autodesk today. I’m putting here for the benefit of other people who encounter the same problem and who might want to know the workaround.

1. Background

Autodesk FBX is a “platform-independent 3D data interchange technology”, or as the rest of us would put it, yet another undocumented 3D file format. It’s useful for getting data out of Autodesk 3ds Max and into other tools. The FBX Software Development Kit comes with a Python interface, which I was trying to install when I ran into this problem.

2. Summary

The Autodesk FBX Python module is distributed without source code. For Max OS X it is distributed as the dynamic library fbx.so, which is built for the i386 architecture only. This means that it does not load on 64-bit Mac OS X systems (which use the x86_64 architecture by default) unless Python is explicitly run with the i386 architecture.

3. Steps to reproduce

On a Mac with a 64-bit processor (e.g. Intel Core 2 Duo) running Max OS X 10.6 (Snow Leopard), follow the instructions to install the Autodesk FBX Python library. Then attempt to import it in Python:

$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fbx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.6/site-packages/fbx.so, 2): no suitable image found.  Did find:
	/Library/Python/2.6/site-packages/fbx.so: mach-o, but wrong architecture

4. Details

The FBX Python module has been compiled for the i386 architecture only:

$ file fbx.so
fbx.so: Mach-O bundle i386

whereas a typical Python module is compiled for multiple architectures:

$ (cd /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/
>  && file zlib.so)
zlib.so: Mach-O universal binary with 3 architectures
zlib.so (for architecture x86_64):	Mach-O 64-bit bundle x86_64
zlib.so (for architecture i386):	Mach-O bundle i386
zlib.so (for architecture ppc7400):	Mach-O bundle ppc

5. Workaround

The FBX library can be loaded by forcing Python to run as a 32-bit application:

$ arch -i386 python2.6
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fbx
>>> 

Note that arch -i386 python doesn’t work (at least on the default Snow Leopard install of Python) because /usr/bin/python isn’t Python, it’s some kind of stub that dispatches to the correct Python executable. If you want to always make Python run as a 32-bit application, then there are a couple of ways to do it (see man 1 python). You can set a key in your preferences file with

$ defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

or you can set the environment variable VERSIONER_PYTHON_PREFER_32_BIT=yes.