如何在Snow Leopard和其他32位/ 64位问题上强制将Python设置为32位 [英] How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions

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

问题描述

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

  $ file / usr / bin / python 

我得到以下三行:

  / usr / bin / python(对于架构x86_64):Mach-O 64位可执行文件x86_64 
/ usr / bin / python(对于架构i386):Mach-O可执行i386
/ usr / bin / python(对于架构ppc7400):Mach-O可执行文件ppc

this似乎表明Python已针对所有三种架构或类似架构进行编译?基于我在尝试安装MySQL时遇到的一些错误,我认为我使用的版本是64位版本。所以有两个问题:


  1. 我怎么知道?


  2. 如何将Python改为32位?


  3. 为什么 arch 来自bash shell,所以比使用不同的编译设置重新编译还要激烈吗?返回 i386 ,这似乎表明当我基于处理器知道我正在运行64位Mac时,我不在 64位模式吗? p>


对不起,这些可能都是新手问题,整个32/64位功能使我和我都感到沮丧'肯定有一些命令/工具可以使此操作更容易。

解决方案


  1. 您可以通过 platform 模块(有关 sys 模块还具有一些简单的助手)


  2. 在Mac OS X上,您可以使用选定的体系结构运行胖二进制文件,例如,



    arch -i386 / usr / bin / python


我做到了建议不要更改/ usr / lib / python本身(使用 lipo 命令)-通过篡改系统文件可以很容易地使系统无法使用。也许从python.org安装一个单独的Python(出于应用目的),同时不给系统留下Python是您可以接受的策略-绝对比更改系统文件更安全!-)



关于第三个问题hmmm,这对我来说是个绊脚石-绝对是superuser.com的问题(以及与Python完全无关,它似乎也与编程完全无关;-)。


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

$ file /usr/bin/python

I get the following three lines:

/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

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. How would I have known that?

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

  3. 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?

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

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

    arch -i386 /usr/bin/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!-)

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位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆