2012年11月29日 星期四

install pygame on mac os x 10.8 (mountain lion)

I highly recommend you to use another way to install pygame:
http://stackoverflow.com/a/14098938/938380

________________ the original way is not recommended ____________
I have struggled to install pygame1.9.1 on my machine for a long time. there are so many dependencies issues.
fortunately, i solved all the issues finally.
I followed the instruction from pygame wiki, but the original step 7 was not working for me.
I have corrected step 7 as below:

1. Installed python but using visual python version. This is based on python 2.7.x
In my system this installs files under Applications and /Library/Frameworks/Python.framework

http://www.vpython.org
From this site:

First, download and install the pure 32-bit Python, Python-2.7.3
(VPython does not work with Mac 64-bit/32-bit Python, but this 32-bit version of Python works fine on 64-bit Macs)

Second, download and install VPython-Mac-Py2.7-5.74

This includes version 1.5.1 of numpy.

The download of Python-2.7.3 is from the vpython site and designed to work with vpython.
You can use the python installer from http://www.python.org. However, you will have to install numpy.
You can get numpy from http://sourceforge.net/projects/numpy/files/

2. Installed the SDL libraries from dmg
http://www.libsdl.org/

SDL  1.2.15
SDL_mixer 1.2.12
SDL_ttf  2.0.11
SDL_image 1.2.12

3. Installed the libjpeg and libpng libraries from dmg
http://ethan.tira-thompson.com/Mac_OS_X_Ports.html

libpng v1.5.4
libjpeg 8c

4. Installed Xcode 4.4 from Apple apps. Need to add command line tools.
To do this start Xcode and go to Preferences under Xcode menu. Choose the Download tab and select Components.
Then install the Command Line Tools.

5. Installed XQuartz. Mountain Lion OS X no longer includes the X11 window system library.
This is different from Lion OS X.
http://xquartz.macosforge.org/landing/

XQuartz-2.7.2.dmg

6. Downloaded pygame tar file from 
http://pygame.org/download.shtml

pygame-1.9.1release.tar.gz 

Decompressed and extracted to create directory pygame1.9.1release

6. Before compilation of pygame:

  a. SDL_x header files refer to SDL as  However, a SDL directory is not under
the include directory of SDL (SDL/Headers). To fix this in a simple way:

    i. Went to directory
          /Library/Frameworks/SDL.framework/Headers
     then made a link as follows:
          ln -s SDL ./

7. Changed to the pygame directory (normally pygame1.9.1release). Then switched to the super user.
However, you can use the sudo command instead.

I set the following compilation flags

export CC='/usr/bin/gcc'
export CFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/opt/X11/include -arch i386'
export LDFLAGS='-arch i386'
export ARCHFLAGS='-arch i386'
ln -s /opt/X11/include/X11/ /usr/local/include/X11
edit src/scale_mmx64.c, and replace movsxl with movslq like this
8. Now execute:
   python config.py
This should find the SDL, jpeg, png, and numpy libraries

   python setup.py build
This will build in the directory before installing. It should complete with no errors.
then
   python setup.py install

9. Confirmed that it worked:

   Out of super user mode and in a terminal shell

   python
   and within python
   import pygame

   this gave no error and a simple pygame program ran fine.


hope this article is helpful