learning python - question about GASP

Discussion in 'Mac Programming' started by OffDog, Aug 7, 2008.

  1. OffDog macrumors newbie

    Joined:
    Aug 7, 2008
    #1
    Hello all

    I am trying to learn Python, following some tutorials and books. I have a web-based 'book' called "How to think like a computer scientist" by Jeffrey Elkner et al. I wondered if someone might know where I have gone wrong with the following issues.....

    I was doing just fine, until he introduced GASP (Graphics API for Students of Python) in Chapter 4. The sticking point was the first line of code he introduces:

    from GASP import *

    I got an error message saying "No module named GASP"

    Now, I went in search of GASP, found it and downloaded it. But it continues to show this message. I also noted that there was an instruction to put it in library/python/2.5/site-packages - which I did. It still didn't run

    I don't fully understand how the import command works here and imagined that it all has something to do with where the files are located. I feel completely mystified - as I have tried moving the GASP - 0.1.1 folder to other places too!

    Just for completeness - I am working mainly with the Terminal rather than with IDLE. Also, when I type, for example

    from Tkinter import *

    it works ok.

    Can anyone help me demystify this for me so I can continue learning some more!

    Thanks in advance
     
  2. pcornwell macrumors newbie

    Joined:
    Aug 11, 2008
    #2
    learning python - question about GASP

    You installed it in the right place - but are you using the right version of Python? I presume that you upgraded to python 2.5? My suggestion would be to check the version of python that is being used on the command line. As I recall Leopard (unless they've changed it recently) ships with 2.3 or 2.4 so it may be looking in the wrong site packages directory hence your problem.

    I'm sure there's an elegant way to fix this but I usually make /usr/bin/python to point to the 2.5 binary - but google it I'm sure thats not the best way!

    As for the import, what that particular version does is copy the contents into your current module rather than use them as an external resource. So from Tkinker import * copies all the objects at that level into your current module.

    Pete
     
  3. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    Are you using the system version of Python supplied by Xcode or one you have downloaded from the net?
     
  4. OffDog thread starter macrumors newbie

    Joined:
    Aug 7, 2008
    #4
    Thank you very much for the replies Pete and Cromulent. Since I wrote that, I shifted to an online tutorial by Alan Gauld which has been excellent and helped me a little bit with some of the issues. (It's all very new to me, so is a bit of a steep learning curve). I have still not totally solved it, but perhaps a little closer....

    Some handy lines I found for checking on the version of Python is via the sys module:
    >>>import sys
    >>>sys.version
    and for the paths that python looks for:
    >>>sys.path

    The version it gives me is 2.5.2 (Cromulent - I seem to have several versions of python on the laptop. Although I did download the latest version from the internet, I think this version being used is actually an older pre-installed version on the laptop.)

    as for location of the current python, this seems to be the line needed:

    $ which python

    and in my case it gives me this address:

    /Library/Frameworks/Python.framework/Versions/Current/bin/python

    So far so good!

    After getting this information, I copied and pasted the GASP folder into the "...Versions/Current/lib/python2.5/sitepackages" folder. And .... hey presto! I get a new and much more complex error message which essentially says that it has found GASP, but is missing Pygame. I have got a Pygame folder and put it into the same one as the Current python folder, but nothing seems to be happening.

    I'm probably going to need to do some additional fiddling around to get the whole thing to work, but feel like I have made some important steps in the roughly the right direction.

    Thanks again for taking time to help out. Much appreciated!

    Dave
     
  5. pcornwell macrumors newbie

    Joined:
    Aug 11, 2008
    #5
    Hi Dave,

    Pygame has some major dependencies that need to be satisfied before it'll run - these might not be being satisfied - the dependencies are all packaged with pygame in the file that can be downloaded from here:

    http://www.pygame.org/download.shtml

    I'd also suggest (as it seems from your post) not to copy files into the site-packages directory directly but when you download - but run "python setup.py install" in the folder you downloaded (wherever you saved it to), that'll put everything in its proper place ... if you are not doing this already.

    Have fun - Python is worth the effort.

    Pete
     
  6. monstermash161, Mar 1, 2011
    Last edited: Mar 1, 2011

    monstermash161 macrumors newbie

    Joined:
    Jan 23, 2011
    #6
    I'm having a similar problem with GASP. I think that I'm using that same textbook where GASP appears in chapter 4. I'm running setuptools and using the easy_install command($ easy_install gasp). It runs for a while and downloads a gasp tarball and then gives me an error saying "no module named dsextras." I've been looking for dsextras but I couldn't find it anywhere, does anybody here know anything that might help? I've then tried to use "from gasp import *" but it gives me "no module named gasp". Thanks a lot if you can help.
     
  7. mattva01 macrumors newbie

    Joined:
    Mar 26, 2011
    #7
    You need to install pygtk

    Pygtk needs to be installed before GASP will work. It should add the dsextras module.
     
  8. a.jfred, May 23, 2011
    Last edited: May 23, 2011

    a.jfred macrumors 6502

    Joined:
    May 28, 2010
    Location:
    Austin, TX
    #8
    I know this is an old thread, but thought I'd ask it here.

    I'm also using the same 'book,' and stuck on Chapter 4. I spent all yesterday in the shell, and followed the few instructions I could find, and still can't GASP to install correctly. I'm using python 2.7 on a 2010 MacBook Pro running Snow Leopard

    At this point, I'm wondering how I can remove 2.7, pygame, and macPorts & just do a clean reinstall of everything.
     
  9. monstermash161 macrumors newbie

    Joined:
    Jan 23, 2011
    #9
    I spent so long in the shell and uninstalling/reinstalling all of this. I gave up about a month ago. If you make any headway, I would really like to know. I wish someone would write a textbook for python 3, anyway.
     
  10. sc4tt3rbr4in macrumors newbie

    Joined:
    May 24, 2011
    #10
    help

    same problem. if anyone has a better way to do this pls let us know!

    Thanks
     
  11. a.jfred macrumors 6502

    Joined:
    May 28, 2010
    Location:
    Austin, TX
    #11
    Sadly, I never managed to get it to work. I tried everything, including removing 2.7 and dropping back to 2.6. I managed to get as far as needing dsextras installed, but nothing I did could get the right files in place. There's just no support for this, and everything I found was so outdated, it was ridiculous.

    My solution? I grabbed Virtualbox and installed the latest version of Ubuntu (11.04, which comes packaged with python 2.7 - and I really didn't feel like paying the $50 to upgrade to Parallels 6, which might or might not work). One quick "hey, install this" command (the one used in the 'How to think like a computer scientist' book), and it works perfectly.

    Not the ideal way, but given I'm using Python as a launchpad to other things, and get back in the mindset of programming, I'm not terribly worried about it right now.
     
  12. rlayne2 macrumors newbie

    Joined:
    Sep 21, 2011
    #12
    Install gasp for mac os lion

    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
    a. 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
    a. 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
    a. make sure your directory is the folder gasp-0.3.4
    7. sudo port –v install py27-gtk
    a. takes about an hour for this step to complete
    8. sudo port uninstall py-game
    a. 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
     

Share This Page