1

I'm currently trying to learn Python and am going through How to Think Like a Computer Scientist: Learning With Python. I have installed Python 2.6.2 on Mac OSX 10.4.11 and am using the IDLE.

At the end of chapter 4 Elkner et al. refer to GASP. However their instructions don't work as when I enter:

>>> from gasp import*

I get:

Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    from gasp import*
ImportError: No module named gasp

I've had a look around on google and can only find outdated methods of installation or pages of gobbledegook. I believe I have to install PyObjC first and haven't been able to accomplish this either.

Can anyone please help me out with some plain English instructions?

lfaraone
  • 49,562
  • 17
  • 52
  • 70
Luke
  • 107
  • 2
  • 6

3 Answers3

2

Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion.

  1. Install macport binary (comes with installer; easy)
  2. sudo port install py-game

    not sure if this is necessary, as it doesn’t appear to cause pygame to be functional for python version 2.7.1 (stock python on lion)

  3. sudo port select --set python python 2.7

    I believe this set the default python version to 2.7.2 which I also believe was downloaded during step 2 (therefore why I think this ends up being a necessary step)

  4. Download setuptools-0.6c11-py2.7.tar
  5. In folder gasp-0.3.4, which appears after clicking on the .tar, place setup.py in the
    gasp folder
  6. sudo python gasp/setup.py install

    make sure your directory is the folder gasp-0.3.4

  7. sudo port –v install py27-pygtk

    takes about an hour for this step to complete

  8. sudo port uninstall py-game

    this step is not necessary for gasp to work; I simply didn’t want any unnecessary stuff on my computer that was downloaded during the second step; however, this step put python 2.7.2 on my computer; could install 2.7.2 separately I guess but this way worked for me; a lot of other unnecessary stuff is installed during this step too but I think it’ll remain even after this command, oh well

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
1

This is actually somewhat of a coincidence; I'm one of the packagers of GASP. On our download page, which is linked by our main project page, there are instructions on how to install it on most major platforms. Hadn't considered OSX, however. Will write something up shortly.

Essentially, install the Official Python from the PSF. Then add MacPorts and run

sudo ports install py-game

Extract the source tarball from the download page linked above to your site-packages directory.

There are also some alternative instructions I found that might work better, as I have not tested the above.

lfaraone
  • 49,562
  • 17
  • 52
  • 70
  • unfortunately it appears PyGame does require PyObjC. I have tried installing from their site but in order to install PyGame and the PyObjC file the installer states that the program requires System Python 2.5 to install. Any ideas? Is this because I have Python 2.6.2 and thats not supported? – Luke Jun 21 '09 at 22:30
  • It's supported. I guess nobody on our development team considered OSX when we wrote GASP, so the instructions are lacking. What it means is that you need to install the python from Python.Org, rather than the one that comes in with OSX. See also http://www.theartfulscientist.com/2008/03/16/how-to-install-pyobjc-pygame-and-gasp-on-mac-os-x-for-python-tutorial/ – lfaraone Jun 21 '09 at 22:31
  • @lfarone: Looks like nobody on your development team reads their own FAQ `https://answers.launchpad.net/gasp-code/+faq/42` which doesn't mention installing a new Python, nor pyObjC – John Machin Jun 21 '09 at 22:42
  • I dont think OSX ships with Python 2.6.2 - Tiger certainly didnt and so I did unstall from Python.org. The PyGame site also says you need to install a version from Python.org and not use the System Python. – Luke Jun 21 '09 at 23:18
  • @john-machin, moderately amusing, since I wrote that. of course, we didn't really look into it too well and as you can see by this post, additional packages are required. – lfaraone Jun 21 '09 at 23:41
  • Note: the MacPorts program is named port not ports. – titaniumdecoy May 30 '10 at 05:21
0

This is an interesting problem faced by most of the readers using "How to Think Like a Computer Scientist : Learning with Python", when they reach 4th chapter.

Now to install GASP, you need to check whether you have python installed on your machine.

Assumption: I am going to assume that you are using Mac.

Type the following command on your terminal,

`$ python -V`  

{If your system has python installed on it, you will get an answer like Python 2.7.1 ( if the version is 2.7.1).}

Once you have python available on your system, you should install PyObjC.

An easy way out is to type on to your terminal prompt,

`$ easy_install pyobjc==2.2` 

{this will install the version 2.2}

Next step is to install pygame package , you can do this in two ways either by downloading the .dmg file or using "homebrew". I prefer the second method.

to install pygame package using "brew" you have to install mercurial first. It's a simple procedure, just type in

$ brew install mercurial

Then type in the following commands,

$ brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi 
$ sudo pip install hg+http://bitbucket.org/pygame/pygame

Next step is to install GASP. Download gasp from https://launchpad.net/gasp-core/+download

Extract the .tar file, you will get a folder structure. Our aim is to copy the folder named "gasp" to the Systems Library folder. To check which folder or version of python is used and to know their correct path type in the following command on terminal.

$ python -c 'import sys, pprint; pprint.pprint(sys.path)'

generally it will print a path similar to '/Library/Python/2.7/site-packages' , you can notice this either as the last line or the second last line of the output that above commands generate.

Copy the gasp folder to the site-packages folder,

$ sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Python/2.7/site-packages/gasp

This should copy all the required files to the location specified as the second argument.

Now go to terminal and type

$ python
>>> import gasp

If everything goes fine, you will not get any error or any messages.

PS: Ensure that in your site-packages directory there are no duplicate copies of pygame/gasp. In case of duplicates, it may throw lots of tantrums. Also, if any of the steps go wrong you may get error "import cairo" some 25th or 26th line on base.py in gasp package.In that event, please clean up your site packages directory by removing pygame and gasp and re-install them, that should solve it.

Also while installing mercurial you may get some warning related to Certificates. You can solve them by typing in following commands,

$ openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650
$ sudo cp dummycert.pem /etc/hg-dummy-cert.pem
$ cd ~
$ nano .hgrc 

{ This will open up an empty .hgrc file }

Type in the following

[web]

cacerts = /etc/hg-dummy-cert.pem

save the above 2 lines by pressing ctrl+ o exit nano by pressing ctrl + x

Thats it. This should solve your problems with GASP installation and enjoy the book " How to Think Like a Computer Scientist" it's a wonderful introduction to the world of computing.

Hari Palappetty
  • 539
  • 6
  • 14
  • You are assuming the user has `easy_install` available; that is not part of the default Python installation. – Martijn Pieters Oct 20 '12 at 20:50
  • Apologies, I didn't have to do any setup unfortunately. It just worked well out of the box. May be the following link will be a good reference for installing the setup tools.http://stackoverflow.com/questions/4111737/python-setuptools-easy-install-setup-mac – Hari Palappetty Oct 25 '12 at 14:25