When I create a virtualenv, python runs in 64-bit even when already set to 32-bit in OSX
My setup is: 2.6.1 python (apple default, snow leopard), virtualenv, and using virtualenvwrapper
Outside the environment, everything runs in 32-bit which is fine. But with a new project I'm going to work on needs django 1.3 and tons of dependencies, so I made a virtualenv.
I've managed to install everything well, except that mysql-python (via pip) gets an error of "mach -o wrong architecture". I've checked my python interpreter with "import sy开发者_JS百科s; sys.maxint" inside the virtualenv and python runs in 64-bit.
I've already set systemwide for python to run in 32-bit via "defaults write com.apple.versioner.python Prefer-32-Bit -bool yes"
Does anyone know why this happens inside the virtualenv?
Much of the "magic" that Apple used to implement their Prefer-32-bit
for the system Pythons in OS X 10.6 is in /usr/bin/python
which then calls the real Python interpreters which are symlinked at /usr/bin/python2.6
and /usr/bin/python2.5
. virtualenv
copies the real interpreter into the virtualenv bin
directory so the Prefer-32-bit
processing is bypassed.
Among the options to ensure 32-bit operation:
Use the
arch
command to invoke the interpreter.$ virtualenv -p /usr/bin/python2.6 ./p $ ./p/bin/python -c 'import sys;print(sys.maxsize)' 9223372036854775807 $ arch -i386 ./p/bin/python -c 'import sys;print(sys.maxsize)' 2147483647
Use
lipo
to extract only the 32-bit arch from the universal binary.$ file ./p/bin/python ./p/bin/python: Mach-O universal binary with 3 architectures ./p/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 ./p/bin/python (for architecture i386): Mach-O executable i386 ./p/bin/python (for architecture ppc7400): Mach-O executable ppc $ cp ./p/bin/python ./p/bin/python-universal $ lipo ./p/bin/python-universal -thin i386 -output ./p/bin/python $ file ./p/bin/python ./p/bin/python: Mach-O executable i386 $ ./p/bin/python -c 'import sys;print(sys.maxsize)' 2147483647
Install and use a newer 32-bit-only Python 2.6 or 2.7 (installers available from python.org)
精彩评论