How to install PyObjC, pygame, and gasp on Mac OS X for Python tutorial
I am going through the Python tutorial “How to Think Like a Computer Scientist” right now, and it is an excellent source for beginner/intermediate Python hands-on learning.
http://openbookproject.net/thinkCSpy/
However, when I got to chapter 8, my fun stopped right away. The author refers to a Python library called GASP (Graphics API for Students of Python) and gives an example and case study of a small game. The thing is, he doesn’t tell you how to install the module and it abruptly interrupts your lovely Python learning experience.
http://openbookproject.net/thinkCSpy/ch08.xhtml
I tried to use easy_install to install most of these, and it always ended up failing for some reason or another.
As I am using Mac OS X Leopard, I will provide the missing instructions for how to get the gasp module installed (and its dependencies) for anyone else who runs into this situation:
How to install PyObjC, pygame, and gasp on Mac OS X
- I assume that you have already installed some version of Python; I am using Universal Python 2.5 from http://www.pythonmac.org/packages/ which is a nice, easy-to-install package and has other prebuilt packages like numpy, wxPython, matplotlib, etc. ready to be installed. You can see other ways to get Python on your Mac at http://wiki.python.org/moin/MacPython/PythonDistributionsForMac
- You will need to install PyObjC, which is also available as a package from http://www.pythonmac.org/packages/ under the 2.5 link.
- Now, you will install pygame from a package (pygame-1.8.0rc4-py2.5-macosx10.4.mpkg.zip) available at http://rene.f0o.com/~rene/stuff/macosx/. This is linked from http://www.pygame.org/download.shtml
- Finally, we get to the part of installing gasp, which is confusing to find in itself. The FAQ page is at https://answers.launchpad.net/gasp-code/+faq/42 but the link to download is wrong. Get it from https://launchpad.net/gasp-code/+download. You will want to download the Code Release which is currently called python-gasp-0.1.1.tar.bz2.
- Extract the bz2 file and there will be a folder inside called gasp. Copy this folder to the /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ directory and you will be in business!
This is the command that I used: sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/gasp
- Open a python session and type import pygame and import gasp to make sure that they are installed correctly.
- Carry on with the great tutorial linked above!
I found it odd that the beginners tutorial left out all of this information. Hopefully this will save someone the two days that it took me to find all of these links, packages, and methods.
Related posts:
- Plotting data on videos – A useful way to convey qualitative and quantitive information Every once in a while, someone makes an impression...
Related posts brought to you by Yet Another Related Posts Plugin.
jde said,
March 27, 2008 @ 11:07 am
Hello, thanks for posting the installation instructions for gasp! I’ve been following “How to Think Like a Computer Scientist” online book. When I try to run the pitch.py code I get the following error:
Traceback (most recent call last):
File “/Users/JonathanEricson/Desktop/pitch.py”, line 80, in
set_speed(120)
NameError: name ’set_speed’ is not defined
Basically a window with a yellow background pops up, and then nothing happens after that. Gasp imports in the Python shell just fine, so I’m not sure why set_speed is not defined if it is part of gasp.
Pardon my failure to use the appropriate CS vernacular — I’m new to this…
Thanks!
Jon
Kris said,
March 27, 2008 @ 1:50 pm
Hey, thanks for the comment.
You know, after all of that trouble that I went through installing gasp, I got those same errors as you. So I emailed the author of “How to Think Like a Computer Scientist” and asked what he thought of the errors. Based on his response and what I found in recent gasp discussion, it looks like gasp is rapidly changing and those methods like set_speed and frames are not being used in the gasp code anymore. So this means that the book is a bit out of date with that example. At this point, I also get gasp to import but have the same yellow screen as you.
Anyway, the author of the book says that a lot of development has been going on with gasp, and that we should wait for the next big release of gasp which should be coming *soon* and that he is also adding another chapter to the book which uses gasp. In the meantime, it looks like gasp 0.2.0beta1 is available, but the 0.1.1 release is still there.
After all that, for now I would just skip the chapter and wait for the new updates – and in the meantime you can view my other post here: http://www.theartfulscientist.com/2008/03/17/the-golden-resource-list-for-python-beginners/ for more resources to learn Python and *lots* of places to go for challenges/exercises/practice.
Happy Pythoning!
- Kris
Niels Olson said,
May 10, 2008 @ 1:13 pm
I’m going through the same book. Definitely a great place to start. A couple of notes on the instructions above:
1) the PyObj package is actually PyObjC
2) the command above is correct. The casual reader should pay attention to the fact that the command actually copies the inner folder gasp, not python-gasp-0.1.1
Kris said,
May 10, 2008 @ 1:33 pm
@Niels Olson
1) Whoops, thanks for the catch. Corrected.
2) I stated that was my command because depending on which distribution of Python you installed, that packages path may be different.
Thanks for the notes!