简体   繁体   English

在Mac上安装Python / PyGame

[英]Installing Python/PyGame on mac

I've been trying to install PyGame with little success. 我一直在尝试安装PyGame,但收效甚微。 I downloaded the 我下载了

pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg

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. 从这个pygame的版本链接并安装它使用向导,但是当我输入导入pygame的进入IDLE我得到了以下信息。

$ 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

What did I do wrong? 我做错什么了? Also, what are the prerequisites for PyGame? 另外,PyGame的前提条件是什么? I'm doing all this on a new computer and I've hardly downloaded anything. 我正在新计算机上进行所有操作,几乎没有下载任何内容。

I'm running OS X Version 10.8.2. 我正在运行OS X版本10.8.2。

I know this thread is a little old, but thought I'd share my experience on this subject... 我知道这个主题有点旧,但是我想分享一下我在这个主题上的经验...

I'm using a 64-bit MacBook Pro running OS Mavericks and python 2.7. 我正在使用运行OS Mavericks和python 2.7的64位MacBook Pro。

Steps: 脚步:

  • 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. 如果您尝试安装一些不同版本的pygame并成功导入并工作,请确保删除/卸载所有这些游戏以重新开始。 I did a simple search in the terminal to see where all of the various pygame folders where located: 我在终端中进行了简单的搜索,以查看所有各种pygame文件夹的位置:

     In Terminal: sudo find / -iname "pygame" 

The results show a list of all the pygame directories, these are the folders that you want to delete. 结果显示所有pygame目录的列表,这些是您要删除的文件夹。 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

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. 还要注意,您可以从上面的代码中删除-i ,它不会确认删除某些文件,但是从终端删除完整目录时请务必小心。

  • 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)! 一旦您的机器清除了以前所有的pygame安装程序,请确保您具有来自python.org的python 2.7,不是IDLE(默认为Mac Python解释器)! This is very important. 这个非常重要。 I use PyCharm and it rocks! 我用的是PyCharm,而且效果不错! 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. 另外,选择适用于32位计算机和64位计算机的版本-这样,您在64位计算机上的pygame 32位安装程序就不会出现问题。 I tried same installation process but with the 64-bit only python 2.7 installation and it didn't work. 我尝试了相同的安装过程,但仅使用64位python 2.7安装,但无法正常工作。 Link provided below: 以下提供的链接:

    Download 32/64-bit Python 2.7 下载32/64位Python 2.7

  • Next, download the 32-bit pygame file for OS X 10.3 and beyond and run the mpkg file created from the dmg. 接下来,下载适用于OS X 10.3及更高版本的32位pygame文件,然后运行从dmg创建的mpkg文件。 Link provided below. 下面提供了链接。

    Download pygame 1.910 release for python 2.7 下载适用于python 2.7的pygame 1.910版本

You should now have a working pygame installation in your python 2.7 package library. 现在,您应该在python 2.7软件包库中安装了有效的pygame安装。 Enjoy. 请享用。

Did you install python from python.org? 您是否从python.org安装了python? Or use the one that came with OS X? 还是使用OS X附带的软件?

If you used the one supplied by Apple, you must download the one from python.org first, then install using that package. 如果您使用了Apple提供的软件,则必须先从python.org下载该软件,然后使用该软件包进行安装。 Or you can try the Lion-pygame package (the link is at the bottom of the Macintosh section of the download page), but it may be incompatible. 或者,您可以尝试Lion-pygame软件包(链接在下载页面的Macintosh部分的底部),但是它可能不兼容。

Did you download python 64-bit or python 32-bit? 您下载的是python 64位还是python 32位?

This can cause major problems if you don't have the right one, if you have 64-bit you can download pygame 64-bit from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame 如果没有合适的版本,这可能会导致严重的问题;如果您使用的是64位版本,则可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame下载pygame 64位版本

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

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