简体   繁体   English

当我创建一个 virtualenv 时,python 运行在 64 位,即使在 OSX 中已经设置为 32 位

[英]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我的设置是:2.6.1 python(苹果默认,雪豹),virtualenv,并使用 virtualenvwrapper

Outside the environment, everything runs in 32-bit which is fine.在环境之外,一切都以 32 位运行,这很好。 But with a new project I'm going to work on needs django 1.3 and tons of dependencies, so I made a virtualenv.但是对于一个新项目,我要处理需要 django 1.3 和大量依赖项,所以我制作了一个 virtualenv。

I've managed to install everything well, except that mysql-python (via pip) gets an error of "mach -o wrong architecture".我已经成功地安装了所有东西,除了 mysql-python(通过 pip)得到“mach -o wrong architecture”的错误。 I've checked my python interpreter with "import sys; sys.maxint" inside the virtualenv and python runs in 64-bit.我已经检查了我的 python 解释器在 virtualenv 中的“import sys; sys.maxint”和 python 以 64 位运行。

I've already set systemwide for python to run in 32-bit via "defaults write com.apple.versioner.python Prefer-32-Bit -bool yes"我已经通过“默认写入 com.apple.versioner.python Prefer-32-Bit -bool yes”将系统范围内的 python 设置为 32 位运行

Does anyone know why this happens inside the virtualenv?有谁知道为什么会在 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 . Apple 用于在 OS X 10.6 中为系统 Python 实现其Prefer-32-bit的大部分“魔法”位于/usr/bin/python中,然后调用真正的 Python 解释器,这些解释器在/usr/bin/python2.6处符号链接/usr/bin/python2.6/usr/bin/python2.5 virtualenv copies the real interpreter into the virtualenv bin directory so the Prefer-32-bit processing is bypassed. virtualenv将真实解释器复制到 virtualenv bin目录中,因此绕过了Prefer-32-bit处理。

Among the options to ensure 32-bit operation:在确保 32 位操作的选项中:

  1. Use the arch command to invoke the interpreter.使用arch命令调用解释器。

     $ 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
  2. Use lipo to extract only the 32-bit arch from the universal binary.使用lipo仅从通用二进制文件中提取 32 位拱门。

     $ 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
  3. Install and use a newer 32-bit-only Python 2.6 or 2.7 (installers available from python.org )安装和使用更新的仅 32 位 Python 2.6 或 2.7(安装程序可从python.org 获得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM