问题描述
我一直在尝试安装PyGame,但收效甚微.我下载了
I've been trying to install PyGame with little success. I downloaded the
pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg
PyGame版本,并使用向导进行了安装,但是当我输入import时pygame进入空闲状态后,我收到以下消息.
version of PyGame from this link and installed it using the wizard, but when I typed import pygame into the IDLE I got the following message.
$ import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
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
我做错了什么?另外,PyGame的前提条件是什么?我正在新计算机上进行所有操作,几乎没有下载任何内容.
What did I do wrong?Also, what are the prerequisites for PyGame? I'm doing all this on a new computer and I've hardly downloaded anything.
我正在运行OS X版本10.8.2.
I'm running OS X Version 10.8.2.
推荐答案
我知道此线程有些旧,但是我想与我分享有关此主题的经验...
I know this thread is a little old, but thought I'd share my experience on this subject...
我正在使用运行OS Mavericks和python 2.7的64位MacBook Pro.
I'm using a 64-bit MacBook Pro running OS Mavericks and python 2.7.
步骤:
-
如果您尝试安装一些不同版本的pygame并试图成功导入并工作,请确保删除/卸载所有这些游戏以重新开始.我在终端中做了一个简单的搜索,以查看所有pygame文件夹的位置:
If you've installed a few different versions of pygame while trying to get the darn thing to import and work successfully, make sure you delete/uninstall all of these to get a fresh start. I did a simple search in the terminal to see where all of the various pygame folders where located:
In Terminal: sudo find / -iname "pygame"
结果显示所有pygame目录的列表,这些是您要删除的文件夹.注意,我在终端中创建了一个新选项卡来执行此操作,因此我可以从上一个选项卡上的搜索中引用目录,并轻松地复制每个目录,而无需进行其他搜索来记住它们的位置:
The results show a list of all the pygame directories, these are the folders that you want to delete. Note, I created a new tab in terminal to do this so I can reference the directories from the search on the previous tab and easily copy each directory without having to do another search to remember where they are:
In Terminal: sudo rm -R -i path/pygame
还请注意,您可以从上面的代码中删除-i
,它不会确认删除某些文件,但是从终端删除完整目录时请务必小心.
Also note, you can take the -i
out of the above code and it won't confirm the deletion of certain files, but BE REALLY CAREFUL when deleting full directories from the terminal.
-
一旦您的计算机清除了以前所有的pygame安装程序,请确保您具有python.org上的python 2.7,而不是IDLE(默认为Mac Python解释器)!这个非常重要.我用的是PyCharm,而且效果不错!另外,选择适用于32位计算机和64位计算机的版本-这样,您在64位计算机上的pygame 32位安装程序就不会出现问题.我尝试了相同的安装过程,但仅使用64位python 2.7安装,因此无法正常工作.下面提供了链接:
Once your machine is clean of all previous pygame installations, make sure you have python 2.7 from python.org, NOT IDLE (default Mac Python Interpreter)! This is very important. I use PyCharm and it rocks! Also, choose the version that works on a 32-bit machine and 64-bit machine - this way you won't have issues with the pygame 32-bit installer on your 64-bit machine. I tried same installation process but with the 64-bit only python 2.7 installation and it didn't work. Link provided below:
接下来,下载适用于OS X 10.3及更高版本的32位pygame文件,并运行从dmg创建的mpkg文件.下面提供了链接.
Next, download the 32-bit pygame file for OS X 10.3 and beyond and run the mpkg file created from the dmg. Link provided below.
您现在应该在python 2.7软件包库中安装了有效的pygame安装.享受.
You should now have a working pygame installation in your python 2.7 package library. Enjoy.
这篇关于在Mac上安装Python/PyGame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!