2

在 OSX 上,我有一个 Python 通用二进制文件,它只包含 32 位代码:

$ 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

我使用这个二进制文件创建了一个 virtualenv:

$ 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.

但是 virtualenv 包含一个包含 32 位和 64 位代码的二进制文件:

$ . 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

我需要使用仅包含 32 位代码而不是 64 位代码的 Python 二进制文件。

我不介意它是一个通用二进制文件,只要它默认以 32 位模式运行,我不必使用“arch -i386”调用它,因为我无法控制这个应用程序的启动方式.

4

1 回答 1

3

我不确定为什么会发生这种行为,但我可以提供一种解决方法。您可以一次将 virtualenv 的 python 剥离到 i386。然后它将不再需要环境标志来确保 32 位:

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
于 2012-06-11T00:27:35.347 回答