Fri, 04 Jan 2013
Compiling cx_Oracle on OS X
Occasionally I need to compile cx_Oracle on OS X and the 32- and 64-bit worlds collide head-on in a mess of "implicit conversion shortens 64-bit value into a 32-bit value" and "file was built for unsupported file format which is not the architecture being linked (x86_64)" errors.
I keep forgetting the various steps needed to make this work correctly so here they are:
- Create a virtualenv with a python interpreter stripped to 32-bit only. In the virtualenv bin directory (
$WORKON_HOME/name_of_virtualenv/bin
):% mv python python.fat % lipo python.fat -remove x86_64 -output python
Doing this saves all the hassles of that "arch", "VERSIONER_PYTHON_PREFER_32_BIT" and "defaults write blah blah" guff and doesn't affect any other virtualenvs. - Now that we have a "thin" Python compatible with the Oracle library, we can build cx_Oracle. Unfortunately even though Python is thin its configuration is not so we need to force things using an obscure environment variable that distutils will pick up:
ARCHFLAGS="-arch i386" pip install cx_Oracle
There, that was easy, wasn't it?