PyGame for Python 3 on OS X Mountain Lion
May 8, 2013
| os-x, python, programming
These are my steps to install PyGame for Python 3 on OS X Mountain lion:
- Download (and unpack) the following:
- PyGame 1.9.1 source: http://www.pygame.org/
- XQuartz-2.7.4: http://xquartz.macosforge.org/
- libpng-1.6.2: http://downloads.sourceforge.net/libpng/
- jpegsrc.v9: http://www.ijg.org/
- Install the png and jpeg libraries:
(cd libpng-1.6.2; ./configure; make; sudo make install)(cd jpeg-9; ./configure; make; sudo make install)- Install XQuartz-2.7.4:
- Run the XQuarts package installer
ln -s /opt/X11/include/X11 /usr/local/include/X11- Install PyGame:
cd pygame-1.9.1release- Edit the
src/scale_mmx64.cfile: replacemovsxlwithmovslq python3 config.pypython3 setup.py buildsudo python3 setup.py install
I already had Numpy (for Python 3) and the SDL libraries installed, but you need them as well. Install them before step 1 above. In Python 3.2 and newer the PyCObject API is replaced by the PyCapsule API. The convert the PyGame code to use PyCapsule perform the following steps in the PyGame source folder (before the "python3 config.py" command in step 4 above):
for i in `grep -r PyCObject . | grep -v Binary - | awk -F : '{ print $1 }' | uniq`; do echo "$i -> $i.org"; cp $i $i.org; donefor i in `grep -r PyCObject . | grep -v Binary - | awk -F : '{ print $1 }' | grep -v '.org' - | uniq`; do cp $i $i.tmp; sed 's/PyCObject_Check/PyCapsule_CheckExact/g' $i.tmp > $i; rm $i.tmp; donefor i in `grep -r PyCObject . | grep -v Binary - | awk -F : '{ print $1 }' | grep -v '.org' - | uniq`; do cp $i $i.tmp; sed 's/PyCObject_AsVoidPtr.*(\([^)]*\))/PyCapsule_GetPointer(\1,NULL)/g' $i.tmp > $i; rm $i.tmp; donefor i in `grep -r PyCObject . | grep -v Binary - | awk -F : '{ print $1 }' | grep -v '.org' - | uniq`; do cp $i $i.tmp; sed 's/PyCObject_FromVoidPtr.*(\([^)]*\)NULL)/PyCapsule_New(\1NULL,NULL)/g' $i.tmp > $i; rm $i.tmp; done
A copy of the original files is kept in files with a .org extension.