本文介绍了如何在 Snow Leopard 和其他 32 位/64 位问题上强制 Python 为 32 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从 Mac 上的 bash shell 运行以下命令时:

When I run the following from a bash shell on my Mac:

$ file /usr/bin/python

我得到以下三行:

/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):    Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

这似乎表明 Python 已经针对所有三种架构或类似的架构进行了编译?我相信,基于我在尝试设置 MySQL 时遇到的一些错误,我使用的版本是 64 位版本.所以两个问题:

this would seem to indicate that Python has been compiled for all three architectures or something like that? I believe, based on some errors I had while trying to setup MySQL, that the version I'm using is the 64-bit version. So two questions:

  1. 我怎么知道的?

  1. How would I have known that?

如何将 Python 改为 32 位?比使用不同的编译设置重新编译更不激烈的事情?

How could I change Python to be 32-bit instead? Something less drastic than re-compile with different compile settings?

为什么 arch 从 bash shell 返回 i386 这似乎表明当我知道基于我的处理器我运行的是 64 位 Mac?

Why does arch from a bash shell return i386 which would seem to indicate I'm not in "64-bit mode" when I know based on my processor I'm running a 64-bit Mac?

抱歉,这些可能都是新手问题,整个 32/64 位问题让我很沮丧,我相信有一些命令/工具可以让这一切变得更容易.

Sorry these are probably all newbie questions, the whole 32/64-bit thing is frustrating the crap out of me and I'm sure there are some commands/tools that would make this easier.

推荐答案

  1. 您可以通过 platform 模块(sys 模块也有一些简单的帮助程序)了解有关您正在运行的 Python 版本的很多信息

  1. You can find out a lot about the Python version you're running via the platform module (the sys module also has a few simple helpers)

在 Mac OS X 上,您可以使用您选择的架构运行胖二进制",例如

On Mac OS X, you can run a "fat binary" with your chosen architecture with, for example,

arch -i386/usr/bin/python

arch -i386 /usr/bin/python

建议更改/usr/lib/python 本身(使用 lipo 命令)——您很容易通过篡改系统文件使系统无法使用.也许从 python.org 安装一个单独的 Python(用于应用程序目的)而让系统 Python 单独存在对你来说是一个可以接受的策略——它绝对比改变系统文件更安全!-)

I do not recommend altering /usr/lib/python itself (with the lipo command) -- you could easily make your system unusable by tampering with system files. Maybe installing a separate Python from python.org (for application purposes) while leaving the system Python alone is an acceptable strategy to you -- it's definitely safer than altering system files!-)

至于你的第三个问题,嗯,这对我来说是个难题——而且绝对是 superuser.com 的问题(而且与 Python 完全无关,它似乎也与编程完全无关;-).

As for your third question, hmmm, this one's a stumper to me -- and definitely a question for superuser.com (as well as completely unrelated to Python, it also seems completely unrelated to programming;-).

这篇关于如何在 Snow Leopard 和其他 32 位/64 位问题上强制 Python 为 32 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:05