For the impatient, jump to the end of this post for the summary of the commands to be invoked. 😉

I have signed up again for a Coursera course for Interactive Python programming to improve my Python programming skills. I am going to sidestep the question if I am going to finish this course for the moment. 😉

The course professors have developed and are using CodeSkulptor to make it easier to create, submit, and grade the course. CodeSkulptor is basically a browser-based Python interpreter that implements a subset of Python 2.x. It absolves the students enrolled in the course from the requirement to install Python in their local machines plus it also allows them to continue working on their code while on different machines (provided they know their work’s randomly generated URL).

The abstraction provided by CodeSkulptor however renders some incompatibilities in running the code locally. This could be a disadvantage for people who wants to work offline, either by choice or by location. Coursera member Jimmy Delgado has provided good quick tutorial on how to run CodeSkulptor code locally. The post is in the Coursera forums but I am replicating it here and then augment it with the steps I have added to make it run on my Ubuntu 14.04 installation.

The core part of Jimmy’s forum posting:

#======== start =======
# Download File
wget https://pypi.python.org/packages/source/S/SimpleGUITk/SimpleGUITk-1.1.3.tar.gz --no-check-certificate

# Uncompress File
tar -xvzf SimpleGUITk-1.1.3.tar.gz

# Move into directory
cd SimpleGUITk-1.1.3

# Set execute priveleges
chmod 755 setup.py

(At this point you can type this for more options: ./setup.py --help)

# For standard install
./setup.py -v build
./setup.py -v install
#======== end =======

The installation will look for the required dependencies and install them if necessary.

If all went well you can copy the following code and save it as testing.py, (courtesy of www.codeskulptor.org).

Jimmy highlights the following to make the GUI testing code run:


Note the line:

import simpleguitk as simplegui

This is the only difference between what's on the website and how you will have to run it locally.

After following the above on my system I still wasn’t able to make the testing page run. The execution fails with the system showing a message that I dont have the “ez_setup” modules in place. I used the instructions from the PyPi site to install the setuptools package which contains the required modules.

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

Running ./testing.py again resulted to … another failure:


Hunting dependencies...
sh: 1: sdl-config: not found
WARNING: "sdl-config" failed!
sh: 1: smpeg-config: not found
WARNING: "smpeg-config" failed!
Unable to run "sdl-config". Please make sure a development version of SDL is installed.
No eggs found in /tmp/easy_install-_ukNIf/pygame-1.9.1release/egg-dist-tmp-rQb1g6 (setup script problem?)
error: Could not find required distribution pygame>=1.9.0

This is easily remedied by installing the pygame and python-tk packages:

sudo apt-get install python-pygame python-tk -y

The python-tk package is required because the CodeSkulptor GUI objects are wrapped or simulated (to my knowledge) by the TKinter libraries. The packages starting at the python-imaging clause are for working with images but is optional at this point. After these are installed the modified test code runs without errors although the text in the black box is cropped because the size of the black box is too small. I dont know enough Python at this point to change that since changing the dimensions of the text inside the canvas.draw_text() function call only changes the offset where the red sample text is rendered. Google searches pointing to the canvas.config(…) function is not helpful as the canvas.config is being reported as non-existing.

This is good enough for now but I recommend installing some additional packages which was needed to run some of the sample code supplied in the forum discussion:

sudo apt-get install -y python-imaging-tk python-imaging libjpeg-dev libtiff-dev libfreetype6-dev

Summary of steps for Ubuntu in a nutshell:

  • sudo apt-get install python-pygame python-tk -y
  • wget https://bootstrap.pypa.io/ez_setup.py -O – | sudo python
  • wget https://pypi.python.org/packages/source/S/SimpleGUITk/SimpleGUITk-1.1.3.tar.gz –no-check-certificate
  • tar -xvzf SimpleGUITk-1.1.3.tar.gz
  • cd SimpleGUITk-1.1.3
  • chmod 755 setup.py
  • ./setup.py -v build
  • sudo ./setup.py -v install
  • and optionally…

  • sudo apt-get install -y python-imaging-tk python-imaging libjpeg-dev libtiff-dev libfreetype6-dev

If you are interested in running a console-based debugger then you can also execute
sudo apt-get install -y python-pudb
There are instructions on how to use blogged in this site.

NOTES:

  • The SimpleGUITk URL is hard-coded to a version. If you are reading this after 2-3 months of posting then then visit https://pypi.python.org/packages/source/S/SimpleGUITk/, select the latest 1.x package if possible and update the targets of the tar and cd steps as appropriate.
  • Coursera user Dennis Rockwell shared a nifty trick he found in the forums on how to maintain compatibility with both systems. It involves encapsulating the import statement in a try-catch block and re-importing the simpleguitk library if the first import statement fails.


    try:
    import simplegui
    except:
    import simpleguitk as simplegui

  • Ingenious in its simplicity. 🙂

ciao!