A. Configuring Ubuntu for Python Development

  1. Vim
  2. GASP
  3. $HOME environment
  4. Making a python script executable and runnable from anywhere

What follows are instructions for setting up an Ubuntu 8.04 ("Hardy Heron") home environment for use with this book. I use Ubuntu GNU/Linux for both development and testing of the book, so it is the only system about which I can personally answer setup and configuration questions.

In the spirit of software freedom and open collaboration, please contact me if you would like to maintain a similar appendix for your own favorite system. I'd be more than happy to link to it or put it on the Open Book Project site, provided you agree to answer user feedback concerning it.

Thanks!

Jeffrey Elkner
Arlington Public Schools
Arlington, Virginia

A.1 Vim

Vim can be used very effectively for Python development, but Ubuntu only comes with the vim-tiny package installed by default, so it doesn't support color syntax highlighting or auto-indenting.

To use Vim, do the following:

  1. From the unix command prompt, run:
    sudo apt-get install vim-gnome
  2. Create a file in your home directory named .vimrc that contains the following:
    syntax enable
    filetype indent on
    set et
    set sw=4
    set smarttab
    map <f2> :w\|!python %<cr>
    

When you edit a file with a .py extension, you should now have color systax highlighting and auto indenting. Pressing the <F2> key should run your program, and bring you back to the editor when the program completes.

To learn to use vim, run the following command at a unix command prompt:

vimtutor

A.2 GASP

Several of the case studies use GASP (Graphics API for Students for Python), which is the only additional library needed to use this book.

To install GASP, do the following:

  1. Add Mathew Gallagher's personal package archive to your apt sources:
    • click System -> Administration -> Software Sources
    • select the Third-Party Software tab
    • click the + Add button
    • paste the following into the APT line: text entry box:
      deb http://ppa.launchpad.net/mattva01/ubuntu hardy main restricted universe multiverse
      
    • click the Close button
    • click the Reload button in The information about available software is out-of-date dialog box
    • click the Close button of the Software Sources window
  2. Install GASP by typing the following at a command prompt:
    sudo apt-get install python-gasp
    

A.3 $HOME environment

The following creates a useful environment in your home directory for adding your own Python libraries and executable scripts:

  1. From the command prompt in your home directory, create bin and lib/python subdirectories by running the following commands:
    mkdir bin lib
    mkdir lib/python
    
  2. Add the following lines to the bottom of your .bashrc in your home directory:
    PATH=$HOME/bin:$PATH
    PYTHONPATH=$HOME/lib/python
    EDITOR=vim
    
    export PATH PYTHONPATH EDITOR
    
    This will set your prefered editor to Vim, add your own lib/python subdirectory for your Python libraries to your Python path, and add your own bin directory as a place to put executable scripts.

A.4 Making a python script executable and runnable from anywhere

On unix systems, Python scripts can be made executable using the following process:

  1. Add this line as the first line in the script:
    #!/usr/bin/env python
    
  2. At the unix command prompt, type the following to make myscript.py executable:
    chmod +x myscript.py
    
  3. Move myscript.py into your bin directory, and it will be runnable from anywhere.

Table of Contents | Index