Question

On OSX, I have a Python universal binary which just contains 32-bit code:

$ file $(python3.2-32)
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2-32: Mach-O universal binary with 1 architecture
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2-32 (for architecture i386): Mach-O executable i386

I create a virtualenv using this binary:

$ virtualenv -p python3.2-32 myenv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2-32
New python executable in myenv/bin/python
Please make sure you remove any previous custom paths from your /Users/jhartley/.pydistutils.cfg file.
Installing distribute........................................................................................................................................................................done.
Installing pip...............done.

But the virtualenv contains a binary with both 32 and 64 bit code:

$ . myenv/bin/activate
(myenv)$ file $(which python)
/Users/jhartley/myenv/bin/python: Mach-O universal binary with 2 architectures
/Users/jhartley/myenv/bin/python (for architecture i386):   Mach-O executable i386
/Users/jhartley/myenv/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64

I need to use a Python binary which contains just 32 bit code, not 64 bit.

I don't mind it being a universal binary, just so long as it runs in 32 bit mode by default, without me having to invoke it using 'arch -i386', since I'm not in control of how this application gets launched.

Was it helpful?

Solution

I'm not exactly sure why this behavior is happening, but I can offer a workaround. You could just strip the virtualenv's python down to i386 one time. Then it would no longer require an environment flag to ensure 32-bit:

source bin/activate
file `which python`
# .../bin/python: Mach-O universal binary with 2 architectures
# .../bin/python (for architecture i386):   Mach-O executable i386
# .../bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
lipo -thin i386 `which python` -output `which python`
file `which python`
# .../bin/python: Mach-O executable i386
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top