简体   繁体   中英

Installing Python/PyGame on mac

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

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

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.

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

I'm using a 64-bit MacBook Pro running OS Mavericks and python 2.7.

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

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

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.

  • 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:

    Download 32/64-bit 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. Link provided below.

    Download pygame 1.910 release for python 2.7

You should now have a working pygame installation in your python 2.7 package library. Enjoy.

Did you install python from python.org? Or use the one that came with OS X?

If you used the one supplied by Apple, you must download the one from python.org first, then install using that package. 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.

Did you download python 64-bit or python 32-bit?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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