简体   繁体   English

为Mac OS X 10.6.8安装Pygame

[英]Installing Pygame for Mac OS X 10.6.8

Using Python 2.7.2. 使用Python 2.7.2。 When I try to import pygame I get this error message: 当我尝试导入pygame时,我收到以下错误消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
    from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper

I'm not exactly sure what this means. 我不确定这意味着什么。 Should I compile pygame myself? 我应该自己编译pygame吗?

The Python 2.7.3 .dmg Mac OS installer installs both 64-bit and 32-bit binaries in: Python 2.7.3 .dmg Mac OS安装程序在以下位置安装64位和32位二进制文​​件:

/Library/Frameworks/Python.framework/Versions/2.7/bin/

There is a 32-bit binary called python2.7-32 in that folder. 该文件夹中有一个名为python2.7-32的32位二进制文​​件。

To use it in the Terminal simply type $ python2.7-32 instead of python 要在终端中使用它,只需键入$ python2.7-32而不是python

To use it in IDLE simply rename the 64-bit python2.7 binary to something like python2.7-64 then rename python2.7-32' to python2.7` and next time you launch IDLE or the Terminal it will use the 32-bit binary. 要使用它在IDLE只需64位重新命名python2.7二进制像python2.7-64然后重命名python2.7-32' to python2.7`和下次启动IDLE或终端将使用32位二进制。 Change it back when you are done. 完成后将其更改回来。

You can also force launch IDLE in 32-bit mode from the Terminal: 您还可以从终端强制以32位模式启动IDLE:

$ arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 -n $ arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 -n

You can create a shell script Automator application to make it easier to launch. 您可以创建一个shell脚本Automator应用程序,以便更容易启动。

The clue is in the last line no matching architecture in universal wrapper . 线索在最后一行中no matching architecture in universal wrapper Most likely you are using precompiled 32-bit binaries on a 64-bit system. 您最有可能在64位系统上使用预编译的32位二进制文​​件。

You can try reinstalling or compiling from scratch but it would probably be far easier to just force python to run in 32-bit. 您可以尝试从头开始重新安装或编译,但强制python以32位运行可能要容易得多。 Lots more info over here in this post . 这篇文章中有更多信息。

What I'd recomend is using a decent Python IDE, like PyCharm. 我建议使用一个体面的Python IDE,比如PyCharm。

I've installed both the 3.3(x64), 3.3(x86) and the 2.7.6 from python.org with both architectures included. 我已经安装了python.org的3.3(x64),3.3(x86)和2.7.6两种架构。

All I have to do is to set up an interpreter configuration for each and I can pick and choose on a project by project level. 我所要做的就是为每个设置一个解释器配置,我可以按项目级别选择项目。

For me this is the definite way of smooth Python Development, contra Python Mangling and manual workarounds. 对我来说,这是顺利Python开发的明确方法,与Python Mangling和手动变通方法相对应。

The Community Version of the PyCharm IDE is even free as in beer! PyCharm IDE的社区版本甚至像啤酒一样免费! Go get it over at JetBrains Site JetBrains网站了解它

It's a breeze to use and behaves the same across both Windows, Linux and OS X. It also acts as a package manager, so you can install different components straight from the IDE and run Console sessions using different configurations. 它在Windows,Linux和OS X上使用和行为都是一件轻而易举的事。它还可以充当包管理器,因此您可以直接从IDE安装不同的组件,并使用不同的配置运行控制台会话。 It also lets you set up virtualenv's easily. 它还可以让您轻松设置virtualenv。

Enough propaganda! 足够的宣传! Go try it out yourself instead. 去试试吧。

And yes, I got PyGame working using this approach... 是的,我让PyGame使用这种方法工作......

I was having the same problem. 我遇到了同样的问题。 I had Python 2.7.2, the installation version for OSX 10.6. 我有Python 2.7.2,OSX 10.6的安装版本。 Here is what I did to fix it: 这是我做的修复它:

1) Deleted my current installation of Python, both from the applications folder and from /Library/Frameworks/Python.framework (I just deleted 2.7.2, left 3.2 alone) 1)从application文件夹和/Library/Frameworks/Python.framework中删除了我当前安装的Python(我刚刚删除了2.7.2,单独留下了3.2)

2) Reinstalled Python 2.7.2, the installation version for OSX 10.3 (my pygame installation file was labeled for OSX 10.3, which prompted me in this direction) 2)重新安装了Python 2.7.2,OSX 10.3的安装版本(我的pygame安装文件标记为OSX 10.3,这促使我朝这个方向发展)

3) Reinstalled pygame 3)重新安装了pygame

Now pygame imports without throwing an error. 现在pygame导入而不会抛出错误。

If you don't want to mess with system file then the easiest way is reinstalling Python 2.7.2 but the 32-bit version only. 如果您不想弄乱系统文件,那么最简单的方法是重新安装Python 2.7.2但仅限32位版本。 Get it here . 得到它在这里

The dmg that includes both 64/32 bits is causing this mess. 包含64/32位的dmg导致了这个混乱。

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

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