Force Python to be 32 bit on OS X Lion

32-bit, cplex, osx-lion, python

Solution

You can use the `lipo` command to create a copy of the Python interpreter with only `i386` support.

:; file /usr/bin/python2.7
/usr/bin/python2.7: Mach-O universal binary with 2 architectures
/usr/bin/python2.7 (for architecture i386): Mach-O executable i386
/usr/bin/python2.7 (for architecture x86_64):   Mach-O 64-bit executable x86_64

:; lipo -thin i386 -output python-i386 /usr/bin/python2.7

:; file python-i386 
python-i386: Mach-O executable i386

:; ./python-i386
Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Then arrange for your existing scripts to call `python-i386`, or (if they use the `/usr/bin/env` trick) rename it to `python` and put it in a directory that's in your `PATH` somewhere before `/usr/bin`.

Note that looking at `platform.architecture()` or even `platform.machine()` doesn't actually tell you if the current process is 32-bit or 64-bit. Those always give 64-bit answers for me. But when I check in Activity Monitor, I can see that my stripped binary is not marked “(64-bit)”, while other processes are.

Problem

I'm trying to use CPLEX within Python on Mac OS 10.7.5. CPLEX appears to only support a 32 bit python. I'm using this in a python shell to check if it's 32 bit: ``` import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32 ``` I've tried these 2 commands as suggested in man 1 python, but neither seem to force 32 bit: ``` export VERSIONER_PYTHON_PREFER_32_BIT=yes defaults write com.apple.versioner.python Prefer-32-Bit -bool yes ``` The only thing that seems to work is this: ``` arch -i386 python ``` However, if I run a script using arch which calls other scripts, they all seem to start up in 64 bit mode. Is there another system wide variable to force it into 32 bit mode?

Original source

Related problems